Discussion:
Capturing onfocus events of iframes with designMode
(too old to reply)
l***@gmail.com
2005-07-15 20:14:25 UTC
Permalink
Hey all,

I have a page where I have two iframes and both iframes have designMode
turned on. Above the iframes, I have some attribute controls for font,
color, etc. I need to be able to capture an onfocus events when either
iframe is selected (for "toolbar context"). However, I'm unable to do
this either by adding an onfocus="" property in the HTMl or by adding
an event in listener (iframe.addEventListener(),
iframe.contentWindow.addEventListener()) in JS.

Can anybody recommend a way to do this?

lpsantil

PS - There seems to be a weird bug where I'm only able to turn
designMode on in JS for more than one frame ONLY if I use a script
src="" to include it. Anybody else notice this?

-------test.html-------
<html>
<head></head>
<body>
<p><iframe id="a" width="200" height="100"
onfocus="alert(0)"></iframe></p>
<p><iframe id="b" width="200" height="100"
onfocus="alert(1)"></iframe></p>
<script src="test.js" type="text/javascript"></script>
</body>
</html>

-------test.js-------
document.getElementById( "a" ).contentWindow.document.designMode =
"on";
document.getElementById( "b" ).contentWindow.document.designMode = "on";
l***@gmail.com
2005-07-15 20:33:15 UTC
Permalink
Just found something that works.

http://permalink.gmane.org/gmane.comp.mozilla.devel.editor/304

lpsantil

-------test.html-------
<html>
<head></head>
<body>
<p><iframe id="a" width="200" height="100"></iframe></p>
<p><iframe id="b" width="200" height="100"></iframe></p>
<script src="test.js" type="text/javascript"></script>
</body>
</html>

-------test.js-------
document.getElementById( "a" ).contentWindow.document.designMode =
"on";
document.getElementById( "a" ).contentDocument.addEventListener(
"click",
{
handleEvent: function( e ){ alert("x"); }
},
false );
document.getElementById( "b" ).contentWindow.document.designMode =
"on";
document.getElementById( "b" ).contentDocument.addEventListener(
"click",
{
handleEvent: function( e ){ alert("y"); }
},
false );

Loading...