0
先進的道歉,如果你看到類似的問題。我嘗試過查找我需要幫助轉換此代碼的內容,但效果不佳,而且很晚。檢查鏈接指的是外部網站
我試圖找出如何改變:
if (link.substr(0, 4) == 'http://localhost','https://localhost')
// If the link starts with http, assume external link.
// In that case, block normal behaviour, insert custom content and navigate after 5 seconds.
event.preventDefault();
基本上它的反向建立不與本地主機開始的任何環節爲接收腳本的其餘部分。儘管一起忽略腳本的鏈接。我試圖使用if,else和return語句,但我不確定我做錯了什麼。再次感謝任何幫助!
<script type="text/javascript">
// Capture all link clicks.
$('a').on('click', function(event) {
// Get the element and its href attribute.
var $element = $(event.target);
var link = $element.attr('href');
if (link.substr(0, 4) == 'http://localhost','https://localhost')
// If the link starts with http, assume external link.
// In that case, block normal behaviour, insert custom content and navigate after 5 seconds.
event.preventDefault();
$element.html("Leaving this website in 5...");
setTimeout(function() {
console.log("This is when the redirect would take place, if not in Staack Snippets");
document.location.href = link;
}, 5000);
}
});
</script>