【问题标题】:How to clear hash from url in chrome如何从 chrome 中的 url 中清除哈希
【发布时间】:2012-05-19 02:37:09
【问题描述】:

我正在使用 url 中的 location.hash,因为我需要在 url 末尾添加一些额外的数据(例如 ...com/page#something)。
但在那之后,我转到其他一些不应该在 url 中包含哈希的页面,并且以某种方式在该 url 中出现哈希 (home.com#hash)。
这只发生在chrome中,firefox很好。 如果有的话,我不想在每个页面上加载清除哈希。 我试过这个:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "noHash", "window.location.hash = ' ';", true);

但这只会在 chrome 中在 url 末尾留下“#”。 知道如何删除它吗?

【问题讨论】:

    标签: c# javascript asp.net url-rewriting scriptmanager


    【解决方案1】:

    试试这个

    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "noHash", "if (window.location.indexOf('#')>-1) window.location = window.location.hash.split('#')[0];", true);
    

    【讨论】:

    • 我把它放在页面加载中,但不知何故它会无限循环。
    • @1110 你肯定在其他地方有问题。上传一个 jsfiddle 什么的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 2012-04-19
    • 2021-02-24
    • 2016-05-12
    • 2020-05-09
    相关资源
    最近更新 更多