My current solution:
function isAccessToWindowRestricted(w) {
try {
return !w.location.href;
} catch (e) {
return true;
}
}
Any better ideas? Is there a 'legal' way without try-catch?
My current solution:
function isAccessToWindowRestricted(w) {
try {
return !w.location.href;
} catch (e) {
return true;
}
}
Any better ideas? Is there a 'legal' way without try-catch?
there is no good way, as there is no way to test that a value in the parent frame even exists without throwing an Exception.
I just tried a few things, including this:
var parentURL = window.parent && window.parent.location && window.parent.location.href;
and no matter what, it'll throw an Exception due to the same origin policy. however, you can check to simply see if you're in an iframe
function checkInFrame( arg ){ arg = arg || window; return arg.parent == window; }
but to my knowledge you have to use a try { ... } catch( ... ) { ... }
block (which is what it's there for).