3

Possible Duplicate:
jQuery .load method not firing on IE9

In IE7 and IE8 this code works, however in IE9, I can't get the .load() function to work on a window handle.

var windowHandle = window.open(url, token, "height=150, width=400,alwaysRaised=yes", false);

$(windowHandle).load(function () {
    alert('This is not getting executed in IE9');
});

EDIT: Working solution (kind of a hack)

window.setTimeout(function () {
    if (windowHandle && windowHandle.document && windowHandle.document.readyState && windowHandle.document.readyState == "complete") {
        windowHandle_Load();
    } else {
        $(windowHandle).load(windowHandle_Load);
    } 
}, 1000);
Community
  • 1
  • 1
CaffGeek
  • 21,856
  • 17
  • 100
  • 184

1 Answers1

1

I suspect that when your URL is in your browser cache, it finishes loading before you install the .load() handler. To try to detect that condition, you can try this:

if (windowHandle.document.readyState == "complete") {
    // already loaded
    alert('This is not getting executed in IE9');
} else {
    // not yet loaded
    $(windowHandle).load(function () {
        alert('This is not getting executed in IE9');
    });
}

The property document.readyState has been in most browsers for awhile, except it was added to Firefox in 3.6.

Presumably, you would break the code you want to execute out into a common function that you could call in these two places rather than have two copies of it.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • That has the code executing, but I had to wrap your code in a 1000 millisecond setTimeout... or put an alert before it. – CaffGeek Nov 25 '11 at 16:14