Hi!
First post here and I am sorry if it's a bit long...
I am using jQuery 1.3.2 and for some reason I am trying to add event
listeners to windows/documents in iframes from the parent window and I
have run into some problems...

Does anyone know why it's possible to bind a listener to the click
event of the document in an iframe but not bind  a listener to the
unload event of the window object (contentWindow) in the same iframe?
At least the unload isn't triggered when the iframe.src is changed.

$(document).ready(function() {
        $("#clickable").click(function() {
                $("#frame1").attr("src", "frame2.html");
        });

        addEvents(window);
});

function addEvents(win) {
        if (win.contentWindow) {
                win = win.contentWindow;
        }

        $(win.document).bind("click", function() {alert("click");});
        $(win).bind("unload", function() {alert("unload");});

        var frames = win.document.getElementsByTagName("iframe");
        for (var i=0; i < frames.length; i++) {
                addEvents(frames[i]);
        }
}

<div id="clickable">Click me</div>
<iframe id="frame1" src="frame1.html"></iframe>

Since it is possible to bind to the click event of the document in the
iframe an unload handler will automatically be registered in IE (to
prevent memory leaks) but this unload handler will not be triggered
when the iframe.src is changed, which in turn will cause an annoying
javascript error (permission denied) when you first alter the
iframe.src and then reload the top window. I have tested with
"beforeunload" with the same result.

Using win.attachEvent/addEventListener works fine...

/Thank you for your time
Henrik


Reply via email to