Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refresh page that uses anchor #tag 1

Status
Not open for further replies.
That's one drawback of using bookmarks. You can avoid this by overriding any bookmarks with a scrollTo - but this assumes you know ehere to scroll to.

If you're always replacing "back to top" links, for example, this would work:

Code:
function patchBackToTopLinks() {
	if (window.scrollTo && (typeof(window.scrollTo) == 'function' || typeof(window.scrollTo) == 'object')) {
		var anchors = document.getElementsByTagName('a');
		for (var loop=0; loop<anchors.length; loop++)
			if (anchors[loop].href.indexOf('#backToTop') != -1)
				anchors[loop].onclick = function() {
					window.scrollTo(0, 0);
					return(false);
				};
	}
}

However, for any other bookmarks, you're pretty much out of luck. You should acceot this as regular browser behaviour, and not worry about it.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Dan,

I have an embeded object game in the html that creates these bookmarks for the object to navigate by. When browser refreshed navagation get stuck at end. I never thought it would be that difficult to have a work around for the browser refresh button, in my case. Since the browser has already rendered would it be possible to re-write the url, to contain a 'begining nav' bookmark, so when user refreshes the browser reads from the url box? or whats Your suggestion? thnks
 
You could always put a function call onload that detects the presence of the bookmark, and replaces the URL with the same one, sans bookmark.

The drawback of this is that the page will refresh twice.

Unavoidable, unfortunately, AFAIK.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
onressy, you might want to also consider using the scrollIntoView() method instead of the bookmarks - you do not have to know the physical pixel location of an element to use that method, and it will prevent the url from being modified

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top