Javascript 脚本不会执行location.href
我的脚本发生了一些奇怪的事情,我不知道它为什么会失败。Javascript 脚本不会执行location.href,javascript,Javascript,我的脚本发生了一些奇怪的事情,我不知道它为什么会失败。 [编辑]我解决了问题,但仍然可以回答为什么会发生这种情况 以下是脚本: <!DOCTYPE HTML> <html> <head> <meta http-equiv='Content-Type'content='text/html;charset=utf-8'> <noscript> <meta http-equiv="refresh" content="0;URL=
[编辑]我解决了问题,但仍然可以回答为什么会发生这种情况 以下是脚本:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv='Content-Type'content='text/html;charset=utf-8'>
<noscript>
<meta http-equiv="refresh" content="0;URL=<?php echo $err_uri;?>"/>
</noscript>
<script>
function e_fout(y,z){
if(typeof tpag=='undefined')tpag='100';
if(typeof y=='undefined')y='999';
if(typeof z=='undefined')z='0';z=tpag+','+y+','+z;
// NAME: URL 1
var url=[window.top.location.protocol, '//',window.top.location.host, window.top.location.pathname,'error/?e='+z].join('');
window.location.href=url;
return false;
}
function go_test(){
// NAME: URL 2
var url=[window.top.location.protocol,'//',window.top.location.host, window.top.location.pathname, 'mytest/test.php'].join('');
alert(url); //<== FOR TEST PURPOSE (3)
window.location.href=url;
return false;
}
var gst=<?php echo ($go_test===true)?9:1;?>;
alert(gst); //<== FOR TEST PURPOSE (2)
if(gst===9){
go_test();
}
// *********************
alert('I'M STILL HERE...') //<== FOR TEST PURPOSE (3)
if(glo!==9){e_fout(1,119);}
</script>
</head>
尝试在不同请求之间使用setTimeout。可能没有足够的时间打开第一页
setTimeout(function(){
alert('hello');
}, 3000);
开发控制台呢?它完全没有错误。两个请求之间可能没有时间。遗憾的是,尝试使用setTimeout或soNot工作。它一直运行到脚本结束。我解决了这个问题,但仍然不知道它为什么会这样。无论如何,谢谢你的时间!
setTimeout(function(){
alert('hello');
}, 3000);