Richard Frovarp wrote:
Jörn Nettingsmeier wrote:
[EMAIL PROTECTED] wrote:
Author: rfrovarp
Date: Fri Jul 20 10:53:59 2007
New Revision: 558075
URL: http://svn.apache.org/viewvc?view=rev&rev=558075
Log:
Prevents backspace in browsers from making the browser to go back a
page.
very useful. i had never encountered this, but after checking it out
on windows, it's really a major issue.
i have a minor nitpick, though:
Modified: lenya/trunk/src/modules/fckeditor/usecases/fckeditor.jx
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules/fckeditor/usecases/fckeditor.jx?view=diff&rev=558075&r1=558074&r2=558075
==============================================================================
<...>
+ <script type="text/javascript"
src="/modules/editors/javascript/disablebackspace.js"> </script>
<...>
- <page:body>
+ <page:body onkeydown="return checkBackspace(event)"
onkeypress="return checkBackspace(event)" >
why should we have to add two snippets to each editor?
in the o'reilly book on javascript, flanagan mentions the concept of
"unobtrusive javascript", i.e. avoiding javascript snippets in the
html as much as possible. i like that idea very much.
what he suggests is to register such handlers via a window.onload call
that is part of the included script file, like so:
function LenyaDisableBackspace() {
var body = document.getElementByTagName('body');
body.onkeydown = new Function(event) {
// checkBackspace function body here
};
body.onkeypress = body.onkeydown;
}
window.onload = LenyaDisableBackspace;
this has the additional benefit of using anonymous nested functions,
which keep the surrounding object namespace clean (you never know if
some editor might have a global checkBackspace function...)
note: this is pseudocode, i haven't tested it yet... just as food for
thought.
best,
jörn
Good idea. I'm not that familiar with javascript. I am unable to get it
to work on body. I can get it to work on document however. Not sure
there is much of a difference in this instance between the two values.
i've done some experiments with this as well, and i've hit a snag:
there can only be one such handler per element, and only one
window.onload function. which means that it's not as modular as it
looks: if two included scripts use the window.onload trick, one will
have its function overwritten...
there is a better event handling mechanism available that avoids this
problem (addEventListener()), but the joke that passes for a browser in
redmond still does not support it :(
you could add global code to the included js like so:
lenyaDisableBackspace();
but it won't work either, because at the time it is executed, a <body/>
node does not exist yet. hrrmpf.
morale: your approach is more robust (but mine looks better :-D)
regards,
jörn
--
jörn nettingsmeier
home://germany/45128 essen/lortzingstr. 11/
http://spunk.dnsalias.org
phone://+49/201/491621
Kurt is up in Heaven now.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]