Link to home
Start Free TrialLog in
Avatar of crazycharlie
crazycharlie

asked on

prevent page anchor tag from creating a history item

I've got a javascript back  (javascript:history.go(-1);) in the href of the page.  The page also has anchor tags href="#1", href="#2", ..., etc.  I'm looking for a way to prevent the anchor tags from creating a history item or to remove the specified history item after the item is clicked.  That way the javascript back button will actually go back to the page that referred this page and not click through the history.

Thank you.

Ch@rlie
Avatar of devic
devic
Flag of Germany image

try this:
===============
<script>
function goTo(where)
{
      document.location.replace(where);
      return false;
}
</script>
<a href=#aaa onclick="return goTo('#aaa')">AAA</a>
<a href=#bbb onclick="return goTo('#bbb')">BBB</a>
Avatar of crazycharlie
crazycharlie

ASKER

devic,

Thanks for the reply.  This doesn't seem to clear the history value at all.  When I click the javascript back (or the browser back for that matter), it still goes from http://www.myurl.com/page.asp#1 to http://www.myurl.com/page.asp.  What I'm wanting it to do is prevent the anchor #1 from creating a listing in the history so the back button will go to the referred page.

Ch@rlie
ASKER CERTIFIED SOLUTION
Avatar of devic
devic
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
devic,

This works perfectly!!! Thanks!

Ch@rlie
Hi,

Your code (the 2nd one) works great on text links but I'm unable to get it to work on image buttons. My pages have a mix of text links to find information further down the same page and image buttons to take you back to the top again - is there any way the code can be applied to both?

Thanks