|
From: Brent on 23 Apr 2008 12:42 The code below correctly sets an iframe to be editable, and then tries to attach an "onkeyup" event to the iframe. Instead of doing that, however, it generates a cryptic "Object required" error in Explorer 7, and doesn't seem to do anything at all in Firefox. Am I missing something really basic? Thanks for any help. --Brent -------------------------------------------------------------------------- function makeEditable(el) { thisEl = el.contentWindow.document; try { if(thisEl.body.contentEditable) {thisEl.body.contentEditable = true;} else {thisEl.designMode = "on";} } catch(e) { alert(e); } thisEl.body.style.fontFamily = "verdana, arial, helvetica, sans- serif"; thisEl.body.style.fontSize = "12px"; thisEl.body.style.margin = "1px"; thisEl.onkeyup = checkKeys; //<--doesn't seem to register the event } function checkKeys(e) { var event = e ? e : window.event; var KeyID = event.keyCode; alert(KeyID); }
From: Henry on 23 Apr 2008 13:21 On Apr 23, 5:42 pm, Brent wrote: > ... , it generates a cryptic "Object required" error in Explorer 7, > and doesn't seem to do anything at all in Firefox. Am I missing > something really basic? > > Thanks for any help. > ------------------------------------------------------------------- > function makeEditable(el) > { > thisEl = el.contentWindow.document; <snip> > thisEl.onkeyup = checkKeys; // ... > > } > > function checkKeys(e) > { > > var event = e ? e : window.event; ^^^^^^^^^^^^ > var KeyID = event.keyCode; <snip> ^^^^^^^^^^^^^ In IE, you are assigning the keyup listener to the document in the IFRAME (as you must) but the code in the assigned function is looking for the event in the window that contains the IFRAME, which is not the window in which the events are happening.
|
Pages: 1 Prev: Pass Initialized Object Reference to Event Next: Alternatives to using global variables? |