Skip to main content

Bug Tracker

Side navigation

#390 closed bug (fixed)

Opened November 14, 2006 04:18PM UTC

Closed April 26, 2007 07:02PM UTC

Last modified March 15, 2012 05:26PM UTC

Can't attach IFrame's load event/IE7

Reported by: Andrey Skvortsov Owned by:
Priority: major Milestone: 1.1.3
Component: event Version: 1.1a
Keywords: Cc:
Blocked by: Blocking:
Description

Try:

var d= document.createElement( "iframe");
$(d).load( function(){alert("ok");});
d.src="";
document.body.appendChild(d);

$(d).bind(...) dosen't work too.

but standard d.attachEvent("onload",...) works fine.

Attachments (0)
Change History (8)

Changed November 17, 2006 09:58AM UTC by joern comment:1

component: ajaxevent
version: 1.0

Changed November 17, 2006 09:22PM UTC by john comment:2

milestone: → 1.1
version: → 1.1

Changed December 24, 2006 09:00PM UTC by Dave comment:3

Just a few notes from some investigations.

The onload event actually belongs to the window object, not the document object; document.onload is an alias for window.onload.

There was this curious comment in jQuery.event.add but d.setInterval==undefined for this case and it may be unrelated anyway:

// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( jQuery.browser.msie && element.setInterval != undefined )
	element = window;

I tried a few other methods, each one by itself to prevent interference; one or both were broken on either IE7 or FF2:

var d= document.createElement( "iframe");
// Tried this and d.src = "http://www.yahoo.com" --nope
d.src="";
// Tried appending first to see if it helped --nope
document.body.appendChild(d); 

// FF2: ok; IE7: Never fires
//$(d).bind("load", function(){alert("ok0");});

// IE7 & FF2: Fires before "done"
//$(d).ready(function(){alert("ok1");});

// FF2: unsupported; IE7: ok
//d.attachEvent("onload", function(){alert("ok2");});

// FF2: ok; IE7: Never fires
//d.onload = function(){alert("ok3");};

// FF2: Never fires; IE7: Fires twice, "interactive" "complete"
//d.onreadystatechange = function(){alert("ok4 "+d.readyState)};

// IE7 & FF2: Never fires
//$(d).bind("onreadystatechange", function(){alert("ok5 "+d.readyState)});

// IE7: Never fires; FF2: Permission Denied exception
//$(d).bind("click", function(){alert("ok6");});

alert("done");

That's as far as I could get.

Changed December 31, 2006 02:38PM UTC by joern comment:4

description: Try:\ var d= document.createElement( "iframe");\ $(d).load( function(){alert("ok");});\ d.src="";\ document.body.appendChild(d);\ \ $(d).bind(...) dosen't work too.\ but standard d.attachEvent("onload",...) works fine.Try:\ \ {{{\ var d= document.createElement( "iframe");\ $(d).load( function(){alert("ok");});\ d.src="";\ document.body.appendChild(d);\ }}}\ \ $(d).bind(...) dosen't work too.\ \ but standard d.attachEvent("onload",...) works fine.

Changed January 02, 2007 08:57PM UTC by aaron.heimli comment:5

I have noticed, in FF 2.0, that attaching events to new windows that load content from a different domain (for example, http://mysite.com has a link that uses window.open() to load http://www.yahoo.com) is pretty much impossible because of the "same origin policy"(1). Perhaps this is related?

(1) http://www.mozilla.org/projects/security/components/same-origin.html

Changed March 24, 2007 05:43PM UTC by john comment:6

need: → Test Case

Changed March 25, 2007 12:40PM UTC by joern comment:7

Related to #939?

Changed April 26, 2007 07:02PM UTC by brandon comment:8

resolution: → fixed
status: newclosed

With the move to DOM Level 2 event handlers in the latest SVN this is now resolved as much as possible.