How to access inside frame

后端 未结 1 411
死守一世寂寞
死守一世寂寞 2020-12-04 00:59

How to access into iframe:

var iframe = document.getElementById(\'sitefield1\');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var          


        
相关标签:
1条回答
  • 2020-12-04 01:38

    You can't directly access frames across origins. In modern browsers you can use postMessage.

    The frame sending the data needs to call postMessage

    top.postMessage({ foo: "bar" }, "*");
    

    and the frame receiving the data needs to register an event listener to look for messages and react to them.

    window.addEventListener("message", receiveMessage, false);
    function receiveMessage(evt) {
        alert(event.data.foo);
    }
    
    0 讨论(0)
提交回复
热议问题