我有 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 ?url= http://imgur.com
当我打开上面的 url 然后它突然重定向,但我想添加 5 秒等待。
在上面的脚本代码中是否可行。
我把那个脚本放在博客标题部分
最佳答案
参见:Javascript - Wait 5 seconds before executing next line
基于此,以下内容可能会起作用:
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);
}
}
关于javascript - 如何在 url 引用脚本中添加 5 秒等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14658971/