Javascript 如何向JS重定向添加延迟
如何在此代码中添加5秒的延时Javascript 如何向JS重定向添加延迟,javascript,Javascript,如何在此代码中添加5秒的延时 <script type="text/javascript"> if (document.location.href.indexOf('url-wording') > -1) { document.location.href = 'http://www.google.com/'; } </script> 如果(document.location.href.indexOf('url-wording')>-1){ docu
<script type="text/javascript">
if (document.location.href.indexOf('url-wording') > -1) {
document.location.href = 'http://www.google.com/';
}
</script>
如果(document.location.href.indexOf('url-wording')>-1){
document.location.href=http://www.google.com/';
}
为什么需要延迟?使用SetTimeOut,我需要延迟,以便跟踪像素可以触发。直接重定向太快了。我不知道为什么,因为它看起来正确,但不起作用。我仍然被直接重定向。请确保删除了所有浏览器缓存,尝试在“匿名窗口”中打开项目,以确保不涉及缓存
if(document.location.href.indexOf('url-wording') > -1) {
setTimeout(function() {
document.location.href = 'http://www.google.com/';
}, 5000); // 5000ms = 5s
}