Inside a function I have an event handler. So far so good. But in that event handler I want to capture Enter pressed and replace that for a HTML.
I've done it like this:
CrossBrowserEventHandler(Editor, 'keyup', function(Event) { myFunctionRef(idname, Event) });
var myFunctionRef = function myFunction(idname, Event)
{
var keyCode;
if (!Event && window.event) {
Event = window.event;
}
if (Event) {
keyCode = (window.Event) ? Event.which : Event.keyCode;
if (keyCode == 13) {
Event.target.ownerDocument.execCommand("inserthtml",false,'<br />');
Event.returnValue = false;
}
}
PushText(idname); /* pushes the input from a rich text iframe to a textarea */
}
The cross browser event handler function looks like this:
function CrossBrowserEventHandler(target,eventName,handlerName)
{
if (target.addEventListener) {
target.addEventListener(eventName, handlerName, false);
}
else if (target.attachEvent) {
target.attachEvent("on" + eventName, handlerName);
}
else {
target["on" + eventName] = handlerName;
}
}
In the first part I capture the keycode 13 (return) and replace it via an execCommand to a HTML line break. It does that, but twice. It doesn't cancel/remove the actual return-pressed event.
Any ideas (besides the standard advice to use a JS framework, which I can't for numerous reasons, one of them being the process of actually learning something)?