Anchor link without History entry

Posted on 2004-04-26
Last Modified: 2008-02-26
I have to make a link to an anchor tag (like <a name="hello">) in the same page that contains this tag, but I need that the a new history entry is created.
I tried with location.replace method but it doesn't seem to work if the target page is the same page that contains the link.
Any ideas?
PS: Sorry for the bad English!
Question by:Giuregol
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
  • 5
  • 3
LVL 36

Expert Comment

ID: 10916166
I'm not sure if this is possible. The location.replace only clears the browser history but doesn't add to it...

LVL 36

Expert Comment

ID: 10916170
Is there a particular reason you need the history to be recorded?


Author Comment

ID: 10916213
As I English i s VERY bad.

 I need that the a new history entry is NOT created !!!

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 36

Expert Comment

ID: 10916285
I am not sure if that is completely possible... In a sense, location.replace replaces the current history with the new one. This means that it will create a new history, but the old one is deleted. I believe this is the only way to go. Is there a reason why the history needs to be suppressed? If the new history is an anchor, then it would be on the same page so it would not really matter.


Author Comment

ID: 10916379
This is the reason:
I have a navigation menu (like in this site.. Home > All Topics > etc..) that not contains links but makes a simple history navigation. If the anchor links create new entries the navigation menu... simply fails!
I need that with an history.back() command I go to the previous page, not to the previous anchor.

LVL 36

Expert Comment

ID: 10916539
I see... I won't ask why you are using history navigation, but I do know that this is a problem. Of course, going back more than one page isn't a problem, to go back two pages, just do:

<a href="javascript:history.go(-2)">Back</a>

You can have a cookie that will keep track of how many links are pressed, but that is tons more complex.

If possible, can you explain to me the needs to using history navigation? If the user hasn't visited the page, then, it won't work.

However, if you have a BACK button on your page and you wish it to work regardless of anchors, in your onLoad statement, you can have a simple check:

<body onload="var ref=document.referral; var locate=window.location; if (ref.substr(0,indexOf('.')) == locate.substr(0,indexOf('.'))) {window.location=history.back();}">

Of course, this would mean after an anchor is clicked and the user click the back button, the page will also jump. If you don't want that to happen, you can include extensions to the URL and get them with JavaScript.


Author Comment

ID: 10916875
I have to use hisory navigation because this part of the site is made by others and I can't modify it.
I have to make pages that prevent menu to fail !
The navigation menu is on a separate frame  and is updated on the load of every page loaded in the main frame.
However the only way to solve the problem is making evry page have one history entry.
The functionality of location.replace method is good (if the old entry is deleted is OK for me) but simply it doesn't happen... the new entry is created but the old still there ! :-(
The location.replace method seems to fail if I add the '#name' on the URL.

Your solution doesn't work on my situation.
The onload event isn't fired when i click an anchor link on the same page.

I tried including extensions to the URL: this method works but the page reloads before scrolling and the users don't like that ( the documents are often too long).

LVL 36

Accepted Solution

Zyloch earned 140 total points
ID: 10916994
This is tricky then. In my honest opinion, I would have to say that the people who made the menu aren't very experienced if they used history navigation...

location.replace actually deletes the whole history if used, so that would be useless to your page. I for now have no ideas. I'll try to think of some at school.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
How to filter by key press ? 6 54
How to check or uncheck a checkbox using the id of the checkbox 2 17
Rotate images for Web Page 11 25
Session on Html 8 38
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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

761 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