I know I can't access data in an iframe which displays a page from another domain. That's perfectly fine, but I'd like to detect, whether the iframe currently shows a page from my domain or something external.
My first attempt would be to try to access
$('iframe')[0].contentWindow.document
wrapped in try {} catch {}
, and if an error is thrown it means I can't access it, and therefore the iframe page must be external.
This sounds like a perfect solution, but the thing is safari posts a "Unsafe JavaScript attempt to access frame with URL" message to the javascript console.
This is not just ugly, but may cause other or future browsers to display explicit security warnings to the user?
Can you try using postMessage?
If there is no response, it is an external domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With