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>