Solved

prevent page anchor tag from creating a history item

Posted on 2004-04-21
5
1,482 Views
Last Modified: 2010-10-28
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
Comment
Question by:crazycharlie
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:devic
ID: 10883965
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
 

Author Comment

by:crazycharlie
ID: 10884025
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
 
LVL 25

Accepted Solution

by:
devic earned 125 total points
ID: 10884344
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
 

Author Comment

by:crazycharlie
ID: 10884494
devic,

This works perfectly!!! Thanks!

Ch@rlie
0
 

Expert Comment

by:Dorian_Fabre
ID: 34012670
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now