如何从 chrome 中的网址中清除哈希

本文关键字:清除 哈希 chrome | 更新日期: 2023-09-27 18:33:41

我在url中使用location.hash,因为我需要在url末尾添加一些额外的数据(如...com/page#something)。
但是在那之后,我移动到其他一些页面,该页面不应该在 url 中包含哈希,并且不知何故在该 url 中有哈希应用器(home.com#hash)。
这只发生在chrome中,火狐很好。我不想在每个页面上加载清除哈希,如果有的话。我已经尝试过这个:

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

但这只在 chrome 中将 '#' 留在网址末尾。知道如何删除它吗?

如何从 chrome 中的网址中清除哈希

试试这个

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