开发者

Cannot get Javascript to navigate to a page

I have this very simple "page":

<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>

For some reason, the script always redirects to itself first, but without the hash. That version of the script then redirects to the intended URL, but with an empty token.

I've tried window.location = t and window.navigate(t) as well, but no luck there. That timeout i开发者_运维百科s also a failed attempt at getting it to work.


Try putting var token = location.hash.toString().substring("#access_token=".length, location.hash.indexOf("&")); var t = "/ri/auth/fbLogin?token=" + encodeURIComponent(token);

Inside of your timeout function.


How silly. Turns out the script worked after all, but the page that it navigated to redirected back to the referrer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜