Q:

Checking if a function is defined in the opener window in IE8

I have a pop-up that allows the opener window to optionally define a callback function, which if defined will be called when the user is done with the pop-up. Based on the advice I've read I'm doing this:
if (window.opener && (typeof window.opener.callbackFunction == 'function')) {
  window.opener.callbackFunction()
}

This works fine in Firefox - when the function is defined, the typeof is "function" as intended. However, in IE8 the typeof is "object" instead. The function is defined normally in the opener, like so:
function callbackFunction() {
  ...
}

Does anybody know why the typeof would be different in IE8? I'm also open to other suggestions as to how to accomplish this. I also tried if (window.opener && window.opener.callbackFunction) but that caused IE8 to blow up when the function wasn't defined.

A:

You can try
if ( window.opener && (typeof window.opener.callbackFunction != 'undefined') {
  window.opener.callbackFunction();
}

I don't have IE currently so I can not test this but believe it will work.

