iframe通信(lg:父页面调用iframe页面的click方法)

获取iframe里的内容

主要的两个API就是contentWindow,和contentDocument

iframe.contentWindow, 获取iframe的window对象

iframe.contentDocument, 获取iframe的document对象

这两个API只是DOM节点提供的方式(即getELement系列对象)

var iframe = document.getElementById("iframe1");

var iwindow = iframe.contentWindow;varidoc = iwindow.document;

console.log("window",iwindow);//获取iframe的window对象

console.log("document",idoc);//获取iframe的document

console.log("html",idoc.documentElement);//获取iframe的html

console.log("head",idoc.head);//获取head

console.log("body",idoc.body);//获取body

console.log(window.frames['ifr1'].window);        // ==window

你可能感兴趣的:(iframe通信(lg:父页面调用iframe页面的click方法))