What is the best way to determine whether a frame is cross-domain? Here's what I have now:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#foo").load(function() {
alert(isCrossDomain(window.frames["foo"]));
});
});
function isCrossDomain(frame) {
try {
var test = frame.document.location.href;
return false;
} catch (e) {
return true;
}
}
</script>
</head>
<body>
<iframe src="frame.html" id="foo" name="foo"></iframe>
</body>
</html>
Basically, the browser throws an exception when I try to access the frame's location.href property if it's cross-domain. But is it safe to rely on this behavior for all browsers? Is there a better way to implement the isCrossDomain function?
Thanks.