The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

String Replacement or Evading the Base Tag

I have a page that uses a "base" tag (that I have to leave in place), and I need to figure out how to get around it for purposes of using bookmark links. In other words, if I have a link that goes like this...

Code:

...href="#bookmark"...

...it goes to the page defined in the base tag instead of to the bookmark on the current page. This is not what I want. I can't hard-code the current page URL, because I need to execute some Javascript on the page when the link is clicked, and using a hard-coded URL causes the page to reload, and then the executed Javascript is lost.

I was able to get it to work doing this...

Code:

...self.location=self.location + '#bookmark'...

...but that's no good because subsequent clicks on the link result in "#bookmark" being appended to the URL over and over again and then it doesn't work. That is...

blahblahblah.html#bookmark#bookmark#bookmark, etc.

So I thought I would do string replacement to get rid of existing instances of the bookmark contained in self.location, and then add it back once...