?
Solved

Anchor link without History entry

Posted on 2004-04-26
10
Medium Priority
?
442 Views
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!
0
Comment
Question by:Giuregol
[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
  • 5
  • 3
10 Comments
 
LVL 36

Expert Comment

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

--Zyloch
0
 
LVL 36

Expert Comment

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

--Zyloch
0
 

Author Comment

by:Giuregol
ID: 10916213
As I said....my English i s VERY bad.

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

0
Independent Software Vendors: 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

by:Zyloch
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.

--Zyloch
0
 

Author Comment

by:Giuregol
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.

0
 
LVL 36

Expert Comment

by:Zyloch
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.

--Zyloch
0
 

Author Comment

by:Giuregol
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).

0
 
LVL 36

Accepted Solution

by:
Zyloch earned 560 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.

--Zyloch
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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…

719 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