我的网址生成如下:仅显示在ie9中
http://myurl.com/#/categories/posts
Run Code Online (Sandbox Code Playgroud)
如何从网址中删除#并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( /#/, "" );
}
Run Code Online (Sandbox Code Playgroud)
删除#/用作.replace( /#\//, "" );提到的Kevin B.
这不是一个真正的JQuery工作 - 为此使用普通的Javascript.
document.location.href = String( document.location.href ).replace( /#/, "" );
Run Code Online (Sandbox Code Playgroud)
编辑 添加@Kevin B的完整性答案
document.location.href = String( document.location.href ).replace( "#/", "" );
Run Code Online (Sandbox Code Playgroud)
只需为锚标记的点击事件添加“return false”即可。
$("#selectorname").click(function(){
if ($.browser.msie && parseInt($.browser.version, 10) === 9 && window.location.href.indexOf("#"))
{
document.location.href = String( document.location.href ).replace( /#/, "" );
}
return false; /* This prevents url from # */
});
Run Code Online (Sandbox Code Playgroud)
要不然
<a href="#" onclick='return false'>Hey click me, I'm # free</a>
Run Code Online (Sandbox Code Playgroud)
或者只是让它变得简单
$("#selectorname").click(function(e){
/* some statements */
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
这可以防止默认操作不被触发。详细信息在这里