여기서는 크로스 도메인없이 index.html에서 b.html에서 dom을 작동시키는 두 가지 방법을 간단히 설명합니다.
예를 들어 : INDEX.html에서 iframe을 가져 오면 JS를 사용하여 Iframe의 DOM 요소를 INDEX에서 작동하는 방법은 무엇입니까?
먼저 index.html 및 iframe에 의해 소개 된 a.html 컨텐츠를 게시하십시오.
색인-> <div> <iframe src = "a.html"frameborder = "0"name = "one"id = "iframeid"> </iframe> </div>
A.html
iframe의 <div id = "dd"> <h1> 요소! </h1> </div>
방법 1 : 방법 1
var d = window.frames [ "one"]. wind
방법 2 : 방법 2.
JS는 동적으로 iframe을 생성하고 삽입합니다
var ifr = document.createElement ( 'iframe'); ifr.src = 'A.html'; document.body.appendChild (ifr); ifr.onload = function () {var doc = ifr.contentDocument || ifr.contentwindow.document; // 조작 B.htmlconsole.log (doc.getElementByid ( "dd"));};두 출력 모두입니다
위의 내용은 귀하에게 소개 된 Iframes에서 DOM의 DOM을 교차 도메인 운영하지 않는 JS에 대한 관련 지식입니다. 나는 그것이 당신에게 도움이되기를 바랍니다!