无法让Javascript导航到页面

时间:2011-05-09 20:45:30

标签: 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=" + encodeURIComponent(token);
console.log(t);
// t is now /ri/auth/fbLogin?token=blablablablablabla
setTimeout(function() {
window.location.href = t;
}, 2000);
</script>

</body></html>

出于某种原因,脚本始终首先重定向到自身,但没有哈希。该版本的脚本然后重定向到预期的URL,但是空token

我也试过了window.location = twindow.navigate(t),但那里没有运气。该超时也是尝试使其起作用的失败。

2 个答案:

答案 0 :(得分:0)

尝试推杆 var token = location.hash.toString()。substring(“#access_token =”。length,location.hash.indexOf(“&amp;”)); var t =“/ ri / auth / fbLogin?token =”+ encodeURIComponent(token);

你的超时功能。

答案 1 :(得分:0)

多么愚蠢。原来这个脚本工作了,但它导航的页面被重定向回引用者。