We have a web page that works fine until we include it in an iframe in another site. Deeplinking works fine in IE and Firefox but not Safari/Chrome (I assume a webkit issue). The problem appears to be in the _getWindow function.
"top.document" in Firefox will throw a securty exception in an iframe
var _getWindow = function() {
try {
top.document;
return top;
} catch (e) {
return window;
}
};
Which is what is expected and "window" will be returned rather than "top". The problem is that a iframe in Safari/Chrome "top.document" will return null and therefor "top" will be returned and null pointer exceptions will occur later in the code.
I change the function to be the following and now it works in and out of an iframe and for all browsers. Since now Safari/Chrome with throw a null pointer exception for "top.document.domain" and return "window" when in an iframe.
var _getWindow = function() {
try {
top.document.domain;
return top;
} catch (e) {
return window;
}
};