emartin24
asked on
Use onLoad function to 'jump' to an internal section (bookmark) on the page.
Hello,
If I had a HTML page like the following:
<html>
<head>
</head>
<body>
<table height="100">
<tr>
<td>blah blah</td>
</tr>
</table>
<table>
<tr>
<td><a name="image"></a><img src="/images/image.jpg" border="0"></td>
</tr>
</table>
</body>
</html>
How would I use JavaScript to cause the page to 'jump' down to the image when the page loads? Hopefully my question makes sence ;)
Thanks,
Eric
If I had a HTML page like the following:
<html>
<head>
</head>
<body>
<table height="100">
<tr>
<td>blah blah</td>
</tr>
</table>
<table>
<tr>
<td><a name="image"></a><img src="/images/image.jpg" border="0"></td>
</tr>
</table>
</body>
</html>
How would I use JavaScript to cause the page to 'jump' down to the image when the page loads? Hopefully my question makes sence ;)
Thanks,
Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why not just use anchors ie the page is called with mypage.htm#image. Or on the onload event put document.location=mypage.h tm#image which will scroll down when the page is opened as just mypage.htm
i must agree with the last comment:
use onload="document.location. replace('m ypage.htm# image')";
this is the best solution.
Nushi.
use onload="document.location.
this is the best solution.
Nushi.
with scroollTo too:
========================== =====
<body onload=scrollTo(0,1500)>
==========================
<body onload=scrollTo(0,1500)>
except that onload="document.location. replace('m ypage.htm# image') will create an infinite loop of loading and reloading the page. Use this instead:
<script type='text/javascript'>
<!--
if(document.location.searc h=="") {
document.location.replace( document.l ocation + "#myimage")
}
//-->
</script>
{Slam}
<script type='text/javascript'>
<!--
if(document.location.searc
document.location.replace(
}
//-->
</script>
{Slam}
Whoops, cancel that comment. If you use an you won't create the loop...
*If you use an anchor you won't create the loop
ASKER
I will try some of the solutions mentioned. Maybe I should have mentioned this before ;), but the reason I don't load the page with mypage.htm#image is because the output is coming from a CGI script.
So the URL is:
http://www.mysite.com/cgi-bin/myprogram.cgi?image=myimage.jpg
I do not think that it works to use:
http://www.mysite.com/cgi-bin/myprogram.cgi?image=myimage.jpg#image
Which is why I was thinking I could use javascript to have the page go directly to the image when it loads. And the reason for this is to prevent having to scroll down to see the image.
Thanks.
So the URL is:
http://www.mysite.com/cgi-bin/myprogram.cgi?image=myimage.jpg
I do not think that it works to use:
http://www.mysite.com/cgi-bin/myprogram.cgi?image=myimage.jpg#image
Which is why I was thinking I could use javascript to have the page go directly to the image when it loads. And the reason for this is to prevent having to scroll down to see the image.
Thanks.
ASKER
third's suggestion did the trick, so I have accepted his answer. Thank you all for your contributions.
Thanks,
Eric
Thanks,
Eric
<body onload="document.anchors['