Skip to content

Commit

Permalink
Fix "Access Denied" exception on window.frameElement reference in chi…
Browse files Browse the repository at this point in the history
…ld iframe with document.domain that differs from parent.
  • Loading branch information
shawnsmith committed Jan 20, 2011
1 parent 96b00a4 commit a5cf129
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ jQuery.event = {
}

// For whatever reason, IE has trouble passing the window object
// around, causing it to be cloned in the process
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
// around, causing it to be cloned in the process leading to a
// weird state where "elem == window" but NOT "elem === window"
if ( elem == window ) {
elem = window;
}

Expand Down

2 comments on commit a5cf129

@shawnsmith
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "if" block canonicalizes "elem" to the window reference used to initialize jQuery. The new code doesn't bother checking "elem !== window" since the "elem = window" assignment is harmless in the cases where "elem == window".

This is a pretty strange piece of code. To understand it, load any page in IE6, IE7, IE8. Then compare the output of these two URLs when entered in the address bar:

  1. javascript:alert(window === window.window);
  2. javascript:alert(window == window.window);

The first URL usually shows "false" in IE and "true" in other browsers. The second URL always shows "true".

I haven't traced back to find out why the original "elem = window" line is necessary. It's older than the 2007 code reorganization that created event.js.

@shawnsmith
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the original version of the "elem = window" from the initial jQuery import https://github.com/jquery/jquery/blame/329d1a3bb2abf5d64bd2fac5801034757619c950/jquery/jquery.js:
if ( element.location ) element = window; // Ughhhhh....

Here's an intermediate version of it from jquery@9e27d8d:

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

As far as I can tell, tests pass on IE7 and IE8 (don't have IE6 handy) without that block of code. Does that mean there's no jQuery test that verifies that this IE hack works correctly? Is it even still necessary?

Please sign in to comment.