View Full Version : window.location without # but with anchor name?

01-06-2011, 11:04 PM

I'm using the following code

var myPage = window.location;

to get the URL of the page and have it replacing
' + myPage + ' in a document.write.

If I have an anchor on a page


I would like the window.location to return


hence without # but with the anchor name.

Is there any way I can have it eliminating the #? (Something like replace # with nothing, take it out or such?)

Thanks for any help you can provide...

01-07-2011, 06:49 AM
Using window.location will always return a # if there is a hash in the URL.

Yes you can strip it, but you need to make sure it's a string first:

var myPage = (window.location.href).replace(/#/, '');

The href is always a string.

01-07-2011, 09:55 AM
Thank you very much John! :) that worked like a charm!