-2

I am trying to scroll down the page using javascript.

I have this code which works fine if if i use javascript:pageScroll() in a link or button:

<SCRIPT LANGUAGE="Javascript">
function pageScroll() {
        window.scrollBy(0,50); // horizontal and vertical scroll increments
        scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
</SCRIPT>

but i need to find out how i can call the pageScroll() function if the user presses enter on their keyboard?

any help would be greatly appreciated.

2
  • add an onkeydown event? I really am not sure what you are asking, did you try anything? Commented Aug 12, 2013 at 14:32
  • stackoverflow.com/questions/905222/… - stackoverflow is not supposed to be a google replacement? Commented Aug 12, 2013 at 14:34

2 Answers 2

8
$(document).keypress(function(e) {
    if(e.which == 13) {
        //do stuff
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

Use jQuery, you might be interested in .keypress(). Here: http://api.jquery.com/keypress/

Also you could have easily avoided this question by doing a simple Google search.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.