我的网址生成如下:仅在 ie9 中显示
http://myurl.com/#/categories/posts
如何从网址中删除 # 并使其在我的其余页面上类似于 http://myurl.com/categories/posts
?谢谢。
我可以这样使用吗?我怎样才能检测到#因为首页没有#。
if ($.browser.msie && parseInt($.browser.version, 10) === 9 && window.location.href.indexOf("#"))
{
document.location.href = String( document.location.href ).replace( /#/, "" );
}
要删除 #/,请使用 .replace(/#\//, "");
正如 Kevin B 提到的
最佳答案
这并不是真正的 JQuery 工作 - 为此使用普通的 Javascript。
document.location.href = String( document.location.href ).replace( /#/, "" );
编辑 添加@Kevin B 的答案以确保完整性
document.location.href = String( document.location.href ).replace( "#/", "" );
关于javascript - jQuery如何从url中删除#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036158/