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();
を基本的にはその逆は、スクリプトの残りの部分を受け取るためにはlocalhostで始まらない任意のリンクを作ることに。リンクはすべて一緒にスクリプトを無視しますが。 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>