【问题标题】:Cannot get Javascript to navigate to a page无法让 Javascript 导航到页面
【发布时间】:2011-05-09 20:45:29
【问题描述】:

我有这个非常简单的“页面”:

<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),但没有运气。该超时也是使其工作的失败尝试。

【问题讨论】:

    标签: javascript url browser


    【解决方案1】:

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

    在你的超时函数内部。

    【讨论】:

    • 我认为这不会有帮助。通过console.log,我看到t的值是正确的。
    • t 的值是正确的在那里。
    【解决方案2】:

    多么愚蠢。事实证明该脚本仍然有效,但它导航到的页面重定向回引荐来源网址。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2020-10-24
      • 2021-06-15
      相关资源
      最近更新 更多