Background first:
In Firefox 3.6.3 on Mac OS X 10.5.8, when entering text in the standard key combination + LeftArrow and Command + RightArrow, move the cursor to the beginning / end of the current line, respectively. However, when using CKEditor, FCKEditor, and the YUI Editor, Firefox does not seem to fully recognize that this is a text area. Instead, it reverts to the default function for those hotkeys that are designed to move backward / forward in the browser history. After that, the text in the editor is also cleared when you return to the page, which very easily releases everything that is being worked on.
I am trying to write a greasemonkey script that I can use to capture events and prevent forward / backward transitions. So far, I could see events with the following, used as a .user.js script in GreaseMonkey:
document.addEventListener('keypress', function (evt) {
var isCmd = evt.metaKey;
if(isCmd)
{
var kCode = evt.keyCode;
if(kCode == 37 || kCode == 39)
{
alert(kCode);
}
}
}, false);
When installing / turning on, pressing the "Ctrl + left | right" key causes a warning with the corresponding code, but as soon as the dialog box closes, the browser moves the page forward / backward. I tried setting new code with evt.keyCode = 0, but that did not work.
So the question is, can this Greasemonkey script be updated to prevent the page from moving backward / forward?
(NOTE: I am also open to other solutions. No need to be a Greasemonkey, this is just the direction I tried. The real goal is to disable the direct / direct function keys.)