13
function Scrolldown() {
        window.scroll(0,300); 
    }

How can I use this function (or a similar one) to automatically scroll down when the page loads? (without clicking a link)

Regards,

taylor

TaylorMac
  • 8,882
  • 21
  • 76
  • 104

5 Answers5

14

Give this a try:

function Scrolldown() {
     window.scroll(0,300); 
}

window.onload = Scrolldown;
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
  • There shouldn't be parentheses with `Scrolldown`. That *calls* the function and assigns its *return value* to `window.onload`, whereas without the parentheses, it assigns the *function* to `window.onload`, which is what you should be after. – Casey Chu Jun 10 '11 at 06:59
8

you could include all of your javascript in an event. This will scroll to an element with an id.

<body onload="window.location='#myID';">
user2445247
  • 81
  • 1
  • 1
4

You could use window.onload:

window.onload = Scrolldown;

I also want to point out that you could use an HTML anchor to indicate where to scroll to, so you don't have to hard-code the pixel value:

<div id="iWantToScrollHere" name="iWantToScrollHere">
    ...
</div>

...which would make your Scrolldown function:

function Scrolldown() {
    window.location.hash = '#iWantToScrollHere';
}
Casey Chu
  • 25,069
  • 10
  • 40
  • 59
0

well, another super simple script is here,

<script type="text/javascript">
window.onload = function(e){ 
    window.scrollBy(1,1);
}

it worked best for me.

0

you could include jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>

and then wrap your scrolling thing in a document ready function:

$(document).ready(function(){

window.scroll(0,300);

});

then after that you don't need to do anything.

:)

JqueryToAddNumbers
  • 1,063
  • 3
  • 14
  • 28