My url generates like this: only shows in ie9
how do I remove # from url and make it like 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( /#/, "" );
}
to remove #/ used .replace( /#\//, "" );
as mentioned Kevin B
My url generates like this: only shows in ie9
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( /#/, "" );
}
to remove #/ used .replace( /#\//, "" );
as mentioned Kevin B
- Are you adding that for purposes of maintaining a history? You're going to need to provide a bit more background on your configuration. – Chords Commented Apr 5, 2012 at 21:20
- Yes, also where do you want to remove it from? In my answer I assumed the address bar, Jones in his assumed all links in the page, it's not quite clear. – gotofritz Commented Apr 5, 2012 at 21:24
4 Answers
Reset to default 9It's not really a JQuery job - use normal Javascript for this.
document.location.href = String( document.location.href ).replace( /#/, "" );
EDIT Adding @Kevin B's answer for completeness
document.location.href = String( document.location.href ).replace( "#/", "" );
Just add 'return false' for anchor tag's click event.
$("#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 # */
});
or else
<a href="#" onclick='return false'>Hey click me, I'm # free</a>
or just make it simple
$("#selectorname").click(function(e){
/* some statements */
e.preventDefault();
});
This prevents the default action not to be triggered. Detailed info here
$("a").attr("href",$("a").attr("href").replace(/#/, ""));
<a href="#" onclick="return false">Hey click me, I'm # free</a>
does the work. I used this to hide # during Bootstrap dynamic tab switch. Thanks
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#i-ab" onclick="return false">ab</a></li>
<li><a data-toggle="tab" href="#i-cd" onclick="return false">cd</a></li>
<li><a data-toggle="tab" href="#i-ef" onclick="return false">ef</a></li>
</ul>