PDA

View Full Version : IFrame MSHTML Editor, capture onkeydown event



skylab
Mar 20th, 2007, 11:40 PM
I have a javascript/MSHTML editor loaded in an IFrame call "msEditor1". It gets composed after the document loads through document.write commands from a JS function. I'm trying to set the editor so whenever a key is typed I capture the key event from the editor and then go from there.

I have a handle to the editor using either one of these:


document.frames.msEditor1.document.body
document.getElementById("msEditor1").document.body
I've tried all these possibilities to add an event, etc, but none of them work:


//document.getElementById("msEditor1").document.body.onkeydown = "alert( 'testing' )"
//document.getElementById("msEditor1").contentWindow.document.onkeydown = "alert( 'testing1' )"
//document.getElementById("msEditor1").contentWindow.document.addEventListener("keydown", editorKeyStroke, true)
//document.getElementById("msEditor1").document.body.addEventListener("keydown", editorKeyStroke, true)
//document.getElementById( "msEditor1" ).document.attachEvent("onkeydown", editorKeyStroke)
//document.getElementById( "msEditor1" ).contentWindow.attachEvent( "keydown", "function(){alert( 'Testing123' );}" )
//document.frames[msEditor1].document.attachEvent("onkeypress", editorKeyStroke);

I can't seem to get the onkeydown event to fire when I type in the editor. Any thoughts? Your help is much appreciated. Thank you.

FJbrian
Mar 22nd, 2007, 08:50 AM
if it's in an iframe wouldn't you be a level down in the "family tree"

ArcticFox
Mar 22nd, 2007, 11:02 AM
I see one use of onKeyPress... is there a reason you're not using onKeyUp events?

skylab
Mar 22nd, 2007, 10:23 PM
What do you mean by another layer down? Am I not already another layer down? If not, what do you mean? :confused:

I'm open to using any function related to key(press)(down)(up) but so far nothing is working.

Any thoughts or help? Thanks.

skylab
Mar 22nd, 2007, 10:47 PM
window.frames['msEditor1'].document.attachEvent("onkeydown", editorKeyStroke)

Where editorKeyStroke is the function being called.

From my previous examples and from the off the cuff remark, "wouldn't you be a level down..." I looked further online for a solution. It appears the only thing wrong with my last failed example was the quotes on the frame name "msEditor" Now it works.

Enjoy! :thumbsup:

FJbrian
Mar 22nd, 2007, 11:06 PM
What do you mean by another layer down? Am I not already another layer down? If not, what do you mean? :confused:
Any thoughts or help? Thanks.

The main page would be the parent to the iframe.

Sorry you found this to be "grossly irresponsible advice" and reported me for my post in this thread. I had no intention whatsoever of offending anyone

ArcticFox
Mar 22nd, 2007, 11:13 PM
if it's in an iframe wouldn't you be a level down in the "family tree"

I don't know, I can pull all sorts of insults out of that statement. :D

FJbrian
Mar 22nd, 2007, 11:23 PM
I don't know, I can pull all sorts of insults out of that statement. :D

I was surprised by it.
I've been coming here for years and love the fount of information this place is. I don't wish to debate this and ruin my posting priviledges here.
Report, sorry, done with it, is all I'm hoping for here
Hopefully you understand AF

ArcticFox
Mar 22nd, 2007, 11:45 PM
What's this all about? Please don't drag me into it. Are you saying I'm unable to understand? You hope I understand? I'm not a charity case, you know, I can understand things on my own without anyone else's blessings.

Wow, what's with all the hostilities all of a sudden? A can't breathe in here...




LOL :D

FJbrian
Mar 23rd, 2007, 05:12 AM
What's this all about? Please don't drag me into it. Are you saying I'm unable to understand? You hope I understand? I'm not a charity case, you know, I can understand things on my own without anyone else's blessings.

Wow, what's with all the hostilities all of a sudden? A can't breathe in here...




LOL :D

no no bro just ending the conversation before I make things worse for myself, that's all. I was hoping you'd understand that, that's it