Solved

prevent page anchor tag from creating a history item

Posted on 2004-04-21
5
1,502 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

752 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