在不同的域中,无法调用方法或直接访问iframe的内容文档。
您必须使[跨文档消息传递。
例如在顶部窗口中:
myIframe.contentWindow.postMessage('hello', '*');在iframe中:
window.onmessage = function(e){ if (e.data == 'hello') { alert('It works!'); }};如果您要将消息从iframe发布到父窗口
window.top.postMessage('hello', '*')


