Javascript: Event In Iframe
I'm building a WYISWYG editor with an iframe with designMode = 'on'. The problem is that I can't use any event on the iframe in Firefox and Opera (IE untested), for example I would
Solution 1:
I would suggest catching the event on the iframe's Document
, and in Firefox at least you need to do this using addEventListener()
rather than onkeyup
. The following will work in all major browsers:
var iframe = document.getElementById("myFrame");
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
function handleIframeKeyUp(evt) {
alert("Key up!");
}
if (typeof iframeDoc.addEventListener != "undefined") {
iframeDoc.addEventListener("keyup", handleIframeKeyUp, false);
} else if (typeof iframeDoc.attachEvent != "undefined") {
iframeDoc.attachEvent("onkeyup", handleIframeKeyUp);
}
Post a Comment for "Javascript: Event In Iframe"