[英]How to add 5 second waiting in url refer script?
我有 url 重定向腳本或 url 引用腳本。
我想添加 5 秒等待,然后 url 重定向到所需的 url。
<script>
var url_index = window.location.href.indexOf('url=');
if (url_index != -1)
{
url_go = window.location.href;
url_go = url_go.substring(url_index + 4);
//document.write(url_go);
window.location.href = url_go;
}
var $_ = function(x){if(!document.getElementById){return;} else{ return document.getElementById(x);}}
</script>
輸出是http://transistortechnology.blogspot.com ? 網址= http://imgur.com
當我在 url 上方打開時,它突然重定向,但我想增加 5 秒的等待時間。
在上面的腳本代碼中是否可能。
我把那個腳本放在博主標題部分
請參閱: Javascript - 在執行下一行之前等待 5 秒
基於此,以下內容應該可行:
url_go = ""
function doRefer() {
var url_index = window.location.href.indexOf('url=');
if (url_index != -1)
{
url_go = window.location.href;
url_go = url_go.substring(url_index + 4);
setTimeout(function () {window.location.href = url_go;}, 5000);
}
}
是的,這很容易做到。 你可以通過調用setInterval來實現。 這里有一些關於如何做的文檔。
這里有一些代碼作為示例(來自網站): setInterval(function(){alert("Hello")},3000);
<script>
var count = 15; // Number of seconds to wait
var counter; // Handle for the countdown event.
function start() {
counter = setInterval(timer, 1000);
}
function timer() {
// Show the number of remaining seconds on the web page.
var output = document.getElementById("displaySeconds");
output.innerHTML = count;
// Decrease the remaining number of seconds by one.
count--;
// Check if the counter has reached zero.
if (count < 0) { // If the counter has reached zero...
// Stop the counter.
clearInterval(counter);
// Start the download.
window.location.href = "URL to open";
//if you want to open in new window then use window.open(url);
return;
}
}
window.addEventListener("load", start, false);
</script>
<div>
Your download will begin in <span id="displaySeconds">15</span> seconds.<br />
</div>
感謝 technovedant 提供此腳本。 我在他的博客上找到了這個
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.