Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Go to an anchor after page load

Posted on 2009-04-19
3
Medium Priority
?
1,058 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:terencepires
3 Comments
 
LVL 1

Accepted Solution

by:
hendrik_johns earned 1000 total points
ID: 24179123
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
 
LVL 13

Assisted Solution

by:numberkruncher
numberkruncher earned 1000 total points
ID: 24179409
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
 
LVL 1

Author Closing Comment

by:terencepires
ID: 31571969
thanks to both of you, i used the onload handler and a function of my own as well

cheers

Terence
0

Featured Post

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!

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
Suggested Courses

580 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