JavaScript does not perform cross-origin operations on the DOM in iframe, jsiframedom
Here, we can simply describe the DOM in B .html in index.html, not in cross-domain situations.
For example, if iframe is introduced in index.html, how can I use JS to operate DOM elements in iframe in index?
First, paste the.html content introduced by index.html and iframe.
index-><div class="d1"><iframe src="a.html" frameborder="0" name="one" id="iframeId"></iframe></div>
A.html
<Div id = "dd">
Method 1:
var d=window.frames["one"].window;d.onload=function(){console.log(d.document.getElementById("dd"));};
Method 2:
JS dynamically creates iframe and inserts
Var ifr = document. createElement ('iframe'); ifr. src = 'a.html '; document. body. appendChild (ifr); ifr. onload = function () {var doc = ifr. contentDocument | ifr.contentcontactdoc ument; // click B .html console here. log (doc. getElementById ("dd "));};
Both outputs are
The above section describes the DOM related knowledge in the iframe file for JS not cross-origin operations. I hope to help you!