You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(react-dom): check if iframe belongs to the same origin
The try / catch block doesn't catch cross domain security error but it
doesn't affect the code execution flow. This mean that the code after
the try / catch block will be executed.
We can do the following To check if the parent page has access to the iframe document:
``javascript`
let hasAccessToDocument = false; // declare an unitialized variable
try {
iframe.contentWindow.location.href; // try to access the iframe
property
hasAccessToDocument = href != null; // This line will be executed if
it has access
} catch (err) {
// Catch block is not executed since the browser throws a cross-domain error
}
return hasAccessToDocument; // This value will be set to true if the parent page has access to the
iframe content.
```
0 commit comments