Can I prevent the document from scrolling when I press the arrow keys?
Very simple: Yes, but don't do it.
Changing how the browser works fundamentally just confuses or angers users, and makes the entire experience less user-friendly. The user should have complete control over how their browser works, not you. It's like blocking menu items from access, or removing context menus, etc.
a source to share
Yes. use something like: document.getElementById ('yourID'). onkeypress = HandleKeyPress;
function HandleKeyPress(e) {
var e = e || window.event;
switch (e.keyCode) {
case e.DOM_VK_LEFT:
case e.DOM_VK_RIGHT:
case e.DOM_VK_UP:
case e.DOM_VK_DOWN:
if (e.preventDefault)
e.preventDefault();
else e.returnValue = false;
}
}
It might not be a good idea though. just make sure you don't notice the best approach.
a source to share
Many seem to say they don't break what the browser does.
I would say the same unless you replace it with similar or better functionality.
I often kill keyboard scrolling on overflow elements because I added a keyboard event to the element where the keyboard down and up keys select items (think of a search box or windows explorer windows).
All the nasty interaction was done with scrolling by default. If the top item is selected then you click "down", it selects the next item and then scrolls down the item and hides the one you just selected.
So, I break the default scrolling and then add my own to scroll to the selected item if it is below (or above) the current scroll. Thus, it behaves exactly like any OS, as you type up and down the files.
Just say break whatever you want, but make sure you know why you are breaking it and the user doesn't notice anything.
a source to share