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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I open a window and scroll to the bottom automatically? 2

Status
Not open for further replies.

mb22

Programmer
Sep 4, 2002
258
US
I have a ASP.NET page that I designed in a 1024/768 pixel resolution. Some users have their resolution set to 800/600 and as a result have to scroll each time to get to the bottom.

What function can I use for the body onload maybe .. so that when the page opens .. it scrolls to the bottom automatically as that will be the optimum view for my users with 800/600 resolution?
 
You can use anchors or scrollTo. Here's an example using scrollTo to get to the bottom onload of the page:
Code:
<script language=javascript>
function scrollToBottom() {
   if (document.body.scrollHeight) {
      window.scrollTo(0, document.body.scrollHeight);
   }
   else if (screen.height) {
      window.scrollTo(0, screen.height);
   }
}
</script>
<body onload='scrollToBottom()'>
<form name=blahForm>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
Test.
</form>
</body>

-kaht

banghead.gif
 
thanks....

how about scrolling half-way down automatically?
 
'same, but divided by 2:

Code:
if (document.body.scrollHeight) {
      window.scrollTo(0, document.body.scrollHeight[b]/2[/b]);
   }
   else if (screen.height) {
      window.scrollTo(0, screen.height[b]/2[/b]);
   }

--Dave
 
Swooped right in there, didn't I?

Here's for you, kaht.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top