Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1520
  • Last Modified:

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
0
crazycharlie
Asked:
crazycharlie
  • 2
  • 2
1 Solution
 
devicCommented:
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>
0
 
crazycharlieAuthor Commented:
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
0
 
devicCommented:
ok, here another version:
============================
<html>
<head>
<script>
function myAnchor()
{
      var s=event.srcElement;
      if(s.tagName.match(/a/i) && !s.href.indexOf(document.location+'#'))
      {
            document.getElementById((s.href.substr(s.href.indexOf('#')+1))).scrollIntoView(true);
            return false;
      }
      return true;
}
</script>
</head>

<body onclick="return myAnchor()">
<a id=top></a>
<a href=#aaa>AAA</a><br>
<a href=#bbb>BBB</a><br>
<br><img src=1.gif width=1 height=1000><br>
<a id=aaa>aaa</a><br>
<a href=#top>top</a><br>
<br><img src=1.gif width=1 height=1000><br>
<a id=bbb>bbb</a><br>
<a href=#top>top</a><br>

</body>
</html>
0
 
crazycharlieAuthor Commented:
devic,

This works perfectly!!! Thanks!

Ch@rlie
0
 
Dorian_FabreCommented:
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now