<html>
<body>
<!-- <iframe id="iff" srcdoc="<div>ok</div>"></iframe> -->
<iframe id="iff" src="data:text/html;charset=utf-8,%3Cdiv%3Eok%3C%2Fdiv%3E"></iframe>
<script>
console.log(document.getElementById('iff').contentWindow.document)
</script>
</body>
</html>
- I set
srcdoc
(triedsrc
also) of<iframe>
, but cannot access the real document of theiframe
(triediframeElement.contentDocument
also). Chrome outputs (also tried Firefox):
I see in Get IFrame's document, from JavaScript in main document that I cannot get the document of a cross-domain iframe, and also learned from Which is the difference between srcdoc="..." and src="data:text/html,..." in an <iframe>? that src
and srcdoc
behaves different about cross-domain behavior. But I tried both, none works.
2. When I append a child to the document body of an iframe (with src
attribute set), the DOM updates but it doesnt show on screen.