2

Is there a way to trigger browser pagedown action with javascript?

var e = document.createEvent('KeyboardEvent');
e.initKeyboardEvent('keydown', true, true, window, false, false, false, false, 34, 0);
document.dispatchEvent(e);

Doesn't seem to work. Keypress is there, but actual scrolling is not happening.

4

2 に答える 2

-2

解決策を試す

window.onkeyup= function(e) {
    if (e.keyCode === 34) {
      alert('PageDown');        
    }
}​

例: http: //jsfiddle.net/hzCFD/4/

于 2012-12-12T11:25:29.127 に答える