当url中包含#符号时,Window.location.href不起作用

时间:2013-02-20 14:52:49

标签: javascript jquery

我有一个弹出式调用,它接受用户凭据并登录用户。 Usully用户也想在登录后访问同一页面。这是我想刷新当前页面的方式。我正在使用

 window.location.href="currentrul";

当我们在url中没有#符号时,这很好用。假设我的网址类似于http://www.test.com/faq#shipping,它将无效。任何建议都很明显。

提前致谢

3 个答案:

答案 0 :(得分:1)

如果要刷新页面,请使用:

window.location.reload();

答案 1 :(得分:0)

不,因为#表示同一页面上的锚点。

  

由哈希标记#引入的片段标识符是可选的   文档URL的最后一部分。它通常用于识别a   该文件的一部分。通用语法在RFC 3986中指定。   URI中的哈希标记分隔符不属于该片段   标识符

来源:http://en.wikipedia.org/wiki/Fragment_identifier

答案 2 :(得分:0)

试试这个:

var currentURL = window.location.href;
if(currentURL.indexOf('#') != -1){
    currentURL = currentURL.substr(0, currentURL.indexOf('#'));
}
window.location.href = currentURL;