主窗口
<script type="text/javascript">
// jQery动态修改url
$('#IframeID').attr("src","/mPath/mTable/Form");
//js动态修改url
document.getElementById("IframeID'").contentWindow.location.href ="http://www.baidu.com";
//加载子窗口数据,做了兼容处理
function iframeOnload(sonData) {
iframe = document.getElementById('IframeID'');//第一句:获取iframe窗口标签
if (iframe.attachEvent) {
iframe.attachEvent("onload", function () {
iframe.contentWindow.setFormData(sonData);//第二句:调用子窗口setFormData并传值
//iframe.contentWindow.document.getElementById("id")//调用子窗口元素
});
} else {
if (iframe.addEventListener) {
iframe.addEventListener("load", function () {
iframe.contentWindow.setFormData(sonData);
})
} else {
iframe.onload = function () {
iframe.contentWindow.setFormData(sonData);
};
}
}
document.body.getElementById('iframe_td_id').appendChild(iframe);//第三句加载子窗口
}
</script>
html代码片断
<div id="iframe_td_id">
<iframe id="IframeID'" name="name" style="padding:0px 0px 0px 20px" height="570px" width="100%" frameborder="0" border="0" marginwidth="0" marginheight="0" scrolling="auto" src="/mPath/mTable/Form"></iframe>
</div>
子窗口
<script type="text/javascript">
//设置表单数据
function setFormData(sonData) {
//处理逻辑
}
// 获取父窗口变量值。
var parentValue =window.parent.document.getElementById("objID").value
//获取父窗口function
window.parent.onAlll(parentValue)
console.log(parentValue);
</script>