Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Same-origin iframe — this works const iframe = document.querySelector("iframe"); const iframeDoc = iframe.contentDocument; // OK if same origin // Cross-origin iframe — this throws a SecurityError try { const crossDoc = iframe.contentDocument; // Error! } catch (e) { console.log("Cross-origin access blocked:", e.message); } // Use postMessage for cross-origin communication instead
Result
Open