iframe子父页面(包括多级嵌套)传值(包括页面元素和js变量)

1.在父窗口中获取iframe中的js方法或者变量

格式:window.frames["iframe的name值"].(js方法名或变量名)
实例:window.frames["iframe1"].createPointAndCenter(child.lng,child.lat);

2.在父窗口中获取iframe中的元素

 

格式:window.frames["iframe的name值"].document.getElementById("iframe中控件的ID")
实例:window.frames["iframe1"].document.getElementById("btnOk");

3.在iframe中获取父窗口的js方法或者变量

 

格式:window.parent.(js方法名或变量名)
实例:window.parent.mapObject;

4.在iframe中获取父窗口的元素

 

格式:window.parent.document.getElementById("iframe中控件的ID")

实例:window.parent.document.getElementById("btn");

5.如果是多级嵌套,例如两级嵌套,在iframe中获取祖父窗口的js变量或方法,(其他同理,有几级就几个parent)

格式:window.parent.parent.(js方法名或变量名)

实例:window.parent.parent.mapObject

6.如果是多级嵌套,例如两级嵌套,在iframe中获取祖父窗口的元素,(其他同理,有几级就几个parent)

格式:window.parent.parent.document.getElementById("iframe中元素的id")

实例:window.parent.parent.getElementById(“btn_close”);

你可能感兴趣的:(iframe子父页面(包括多级嵌套)传值(包括页面元素和js变量))