Go to an anchor after page load

hi there,

i would like to a page to go to a particular anchor when it finishes loading. I tried the "myPage#myAnchor" but it doesn't work well since the page has lots of elements to load up.
I tried to use the "setTimeout" function without success...

Any idea ?

Thanks by advance,

Terence
LVL 1
terencepiresAsked:
Who is Participating?
 
hendrik_johnsCommented:
Try to use the onload event in the body tag (<body onload=".....">) .

The onload is called when the page has loaded, therefor all you data on the page should be there.

Cheers,

Hendrik
0
 
numberkruncherCommented:
Have you tried something like the following:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Demo Page</title>
		<script type="text/javascript">
			window.onload = function() {
				window.location.href = '#myAnchor';
			}
		</script>
	</head>
	<body>
		<h1>Demo Page</h1>
		<div>
			Lots of text</br><br/><br/><br/><br/><br/><br/><br/><br/><br/></br><br/><br/><br/><br/><br/><br/><br/><br/><br/>
			Lots of text</br><br/><br/><br/><br/><br/><br/><br/><br/><br/></br><br/><br/><br/><br/><br/><br/><br/><br/><br/>
			Lots of text</br><br/><br/><br/><br/><br/><br/><br/><br/><br/></br><br/><br/><br/><br/><br/><br/><br/><br/><br/>
		</div>
		<div id="myAnchor">Anchor!</div>
	</body>
</html>

Open in new window

0
 
terencepiresAuthor Commented:
thanks to both of you, i used the onload handler and a function of my own as well

cheers

Terence
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.