View Full Version : iframes and onkeydown, compatible?

05-04-2004, 10:28 PM
Are iframes compatible with onkeydown? Let me back up and make this harder (or easier?)... Can I use onkeydown on and iframe that is in docmode (designmode)? If I can, can I interpret only the keystroke I want ("esc") and the rest will go through to the iframe in docmode?

I have a help system that runs on local machines. It has a 2 frame page that comes up to browse (left side) and diplay (right side) data. I want to be able to parent.window.close() when they press "ESC." I got it working everywhere EXCEPT when they are in the editable iframe. The editable iframe is what they use to create they're own helps.

In summary I want to catch the "ESC" key in an EDITABLE (that's what's making it hard) iframe and use that to close the window and let every other keystroke go by.


05-04-2004, 11:25 PM
quickly tried this; seems to work...

<body onload="ifr.document.designMode='on'">
<iframe id="ifr" src="about:blank" width="25%" height="25%"></iframe>
<script type="text/JScript">
function ifr.document::onkeypress(){
if(event.keyCode == 27){alert("ESC");}

Roy Sinclair
05-04-2004, 11:33 PM
swmr's idea will work right up to the point where you load a document into the iframe, then you'll have to link up the events in the iframe to your functions again.

You have to remember that an IFRAME is like a separate browser window that's just embedded inside your web page. What's contained within that iframe isn't part of your page, you can hook events from that iframe to your page as long as the iframe is looking at a page from your web server, otherwise you can't hook it's events since that would allow cross-site scripting.

05-05-2004, 12:12 AM
that should work because I dynamicaly control the page being built into the iframe anyway... :thumbsup: