Solved

Anchor link without History entry

Posted on 2004-04-26
10
402 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 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.

--Zyloch
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

708 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

19 Experts available now in Live!

Get 1:1 Help Now