photo_tom
photo_tom

Reputation: 7342

Intercept PageUp / PageDown keydown events in Chrome Browser

I have some input elements that the users are request special behavior on pageup / pagedown keys to modify value in input element. What the users do not want is to have the scrolling region they are editing in also do a page up/down scroll. I have it working correctly in Firefox and IE8.

However, in Chrome, I cannot find a way to prevent the browser itself from using these keyboard events to scroll the region. Before anyone suggests it, calling e.stopPropagation() or e.immediateStopPropagation() does not solve the problem in Chrome. It works fine in Firefox and IE8.

Also, the page up/down behavior is to only modified for these special input fields. For all others, page up/down is to work normally.

You can see a working demo at http://jsfiddle.net/photo_tom/CN4UZ/.

Upvotes: 3

Views: 4208

Answers (2)

Daniel A. White
Daniel A. White

Reputation: 190945

I used e.preventDefault(). Works in Chrome 16.

http://jsfiddle.net/CN4UZ/5/

Upvotes: 3

Naftali
Naftali

Reputation: 146300

Works fine in Chrome for me.

Google Chrome   17.0.963.12 (Official Build 114667) dev-m
OS  Windows
WebKit  535.11 (@102901)
JavaScript  V8 3.7.12.6
Flash   11,1,102,55
User Agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11
Command Line    "C:\Users\..\AppData\Local\Google\Chrome\Application\chrome.exe" --no-startup-window --flag-switches-begin --enable-print-preview --flag-switches-end
Executable Path C:\Users\..\AppData\Local\Google\Chrome\Application\chrome.exe
Profile Path    C:\Users\..\AppData\Local\Google\Chrome\User Data\Default

If you do not have my build:

Try using return false: http://jsfiddle.net/maniator/CN4UZ/4/

Upvotes: 0

Related Questions