Commit c20f858
committed
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.
```1 parent 2aabdf5 commit c20f858
1 file changed
+18
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
43 | 56 | | |
44 | 57 | | |
45 | 58 | | |
46 | 59 | | |
47 | 60 | | |
48 | 61 | | |
49 | 62 | | |
50 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
51 | 68 | | |
52 | 69 | | |
53 | 70 | | |
| |||
0 commit comments