调用iframe中的js函数

710 阅读1分钟

在父页面调用iframe中的函数

js

var iframe = window.document.getElementById("iframeId");

iframe.contentWindow.methodName();


jquery

var iframe2 = $("#iframeId")[0];

iframe2.contentWindow.methodName();


在调用同级iframe中的函数

js

var iframe1 = window.parent.window.document.getElementById("iframeId");

iframe1.contentWindow.methodName();


jquery

var iframe2 = $("#iframeId",window.parent.document)[0];

iframe2.contentWindow.methodName();