无法获取Javascript以导航到页面
我有一个非常简单的页面:无法获取Javascript以导航到页面,javascript,url,browser,Javascript,Url,Browser,我有一个非常简单的页面: <html> <head> </head> <body>Handling... <script> var token = location.hash.toString().substring("#access_token=".length, location.hash.indexOf("&")); var t = "/ri/auth/fbLogin?token=" + encodeURICompone
<html>
<head>
</head>
<body>Handling...
<script>
var token = location.hash.toString().substring("#access_token=".length, location.hash.indexOf("&"));
var t = "/ri/auth/fbLogin?token=" + encodeURIComponent(token);
console.log(t);
// t is now /ri/auth/fbLogin?token=blablablablablabla
setTimeout(function() {
window.location.href = t;
}, 2000);
</script>
</body></html>
出于某种原因,脚本总是首先重定向到自身,但没有哈希。然后,该版本的脚本重定向到预期的URL,但带有空标记
我也尝试了window.location=t和window.navigatet,但没有成功。该超时也是使其正常工作的失败尝试。尝试放置
var token=location.hash.toString.substringaccess_token=.length,location.hash.indexOf&;
var t=/ri/auth/fbLogin?token=+encodeURIComponenttoken
在你的超时函数里面。多傻啊。事实证明,脚本毕竟起了作用,但它导航到的页面重定向回了推荐人。我认为这没有帮助。通过console.log,我看到t的值是正确的。t的值是正确的。是的,但这可能是一个范围问题,因为您没有在setTimeout内向函数传递任何内容,在这种情况下,我看不出有任何理由不能将代码放在其中。