jQuery如何从网址中删除# [英] jQuery how to remove # from url

查看:98
本文介绍了jQuery如何从网址中删除#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网址生成如下:仅在ie9中显示

My url generates like this: only shows in ie9

http://myurl.com/#/categories/posts

如何从网址中删除#,并使其在其余页面上像http://myurl.com/categories/posts一样?谢谢.

how do I remove # from url and make it like http://myurl.com/categories/posts on rest of my pages? thanks.

我可以这样使用吗?我如何检测#导致首页没有#.

can i use like this? how can I detect # cause front page has no #.

if ($.browser.msie  && parseInt($.browser.version, 10) === 9 && window.location.href.indexOf("#")) 
    {
        document.location.href = String( document.location.href ).replace( /#/, "" );
    }

删除#/,如提到的Kevin C所使用的.replace( /#\//, "" );

to remove #/ used .replace( /#\//, "" ); as mentioned Kevin B

推荐答案

这并不是真正的JQuery作业-为此使用常规Javascript.

It's not really a JQuery job - use normal Javascript for this.

document.location.href = String( document.location.href ).replace( /#/, "" );

编辑 添加@Kevin B的答案以保持完整性

EDIT Adding @Kevin B's answer for completeness

document.location.href = String( document.location.href ).replace( "#/", "" );

这篇关于jQuery如何从网址中删除#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆