Thursday, June 19, 2008

execScript does not work in Firefox

I came across this issue recently when I was testing our admin web pages in Firefox.
What the page was trying to do was to run some custom javascript function from a parent window using the window execScript() function.

The problem is that the window.execScript() does not work in Firefox. Apparently, window.execScript() is only available in IE (http://ajaxian.com/archives/evaling-with-ies-windowexecscript).

The work around to this is as follows:

//assume parentWnd variable has reference to the parent window.
if (parentWnd.execScript) {
parentWnd.execScript(sScript); //for IE
} else {
eval('self.opener.' + sScript); //for Firefox
}