Solved

prevent page anchor tag from creating a history item

Posted on 2004-04-21
5
1,477 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

758 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

23 Experts available now in Live!

Get 1:1 Help Now