[jQuery] problem with iFrame in FF (again)
Ok, I copied this code from the Mozilla developer center but funny enough, it works under IE6 and not on Firefox:
<br style="font-family: courier new,monospace; color: rgb(51, 204, 0);"><span style="font-family: courier new,monospace; color: rgb(0, 102, 0);">
/**</span><br style="font-family: courier new,monospace; color: rgb(0, 102, 0);"><span style="font-family: courier new,monospace; color: rgb(0, 102, 0);"> * First I define the function.</span><br style="font-family: courier new,monospace; color: rgb(0, 102, 0);">
<span style="font-family: courier new,monospace; color: rgb(0, 102, 0);"> * @param String aID - ID of the iFrame I want to access.</span><br style="font-family: courier new,monospace; color: rgb(0, 102, 0);"><span style="font-family: courier new,monospace; color: rgb(0, 102, 0);">
* @return String - the query needed to access the iFrame as appropiate in W3C or MS mode.</span><br style="font-family: courier new,monospace; color: rgb(0, 102, 0);"><span style="font-family: courier new,monospace; color: rgb(0, 102, 0);">
*/</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace; color: rgb(153, 51, 0);"><span style="color: rgb(0, 0, 153);">function</span> getIFrameDocument(aID){</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);">
<span style="font-family: courier new,monospace; color: rgb(153, 51, 0);"> <span style="color: rgb(0, 0, 153);">if</span> (document.getElementById(aID).contentDocument)</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);">
<span style="font-family: courier new,monospace; color: rgb(153, 51, 0);"> <span style="color: rgb(0, 0, 153);">return</span> document.getElementById(aID).contentDocument;</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);">
<span style="font-family: courier new,monospace; color: rgb(153, 51, 0);"> <span style="color: rgb(0, 0, 153);">else</span></span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);"><span style="font-family: courier new,monospace; color: rgb(153, 51, 0);">
return document.frames[aID].document;</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);"><span style="font-family: courier new,monospace; color: rgb(153, 51, 0);">}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace; color: rgb(0, 102, 0);">/** And now I use inside $(document).ready. */</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace; color: rgb(153, 51, 0);">$(document).ready(<span style="color: rgb(0, 0, 153);">function</span>(){</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);">
<span style="font-family: courier new,monospace;"><span style="color: rgb(153, 51, 0);"> console.log(getIFrameDocument(<span style="color: rgb(51, 51, 153);">"foo"</span>).designMode);</span> <span style="color: rgb(0, 102, 0);">
/** returns "off". */</span></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace; color: rgb(153, 51, 0);"> getIFrameDocument(<span style="color: rgb(51, 51, 153);">
"foo"</span>).designMode = <span style="color: rgb(51, 51, 153);">"On"</span>;</span><br style="font-family: courier new,monospace; color: rgb(153, 51, 0);"><span style="font-family: courier new,monospace;">
<span style="color: rgb(153, 51, 0);"> console.log(getIFrameDocument(<span style="color: rgb(51, 51, 153);">"foo"</span>).designMode);</span> <span style="color: rgb(0, 102, 0);">/** returns "on". */</span>
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"><span style="color: rgb(153, 51, 0);">});</span>
</span>
So it works perfectly in IE6 leaving the iFrame with ID = "foo" with design mode "on" so you can edit it. In Firefox the console logs the function's success at changing the mode when actually it is still "off". The function seems to be well written: if once everything is loaded you type
<span style="font-family: courier new,monospace; font-weight: bold;">getIFrameDocument("foo").designMode = "On"</span> in Firebug, the mode changes effectively, so I'm thinking that this might be due to an incompatibility with the
<span style="font-family: courier new,monospace; font-weight: bold;">$(document).ready</span> statement.
Anyone sees anything wrong in the code or has ideas or suggestions? thanks.<span style="font-family: courier new,monospace;">
</span>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/