iframe之父子页面通信】的更多相关文章

iframe之父子页面通信 1.获取 子页面 的 window 对象  在父页面中,存在如下两个对象 window.frames document.iframeElement.contentWindow 可以获取到 子页面 window 对象 // iframe id document.getElementById('menuIframe').contentWindow // iframe name window.frames['menuIframe'].window // iframe ind…
一.同域下父子页面的通信 1.父页面调用子iframe页面 (1)通过iframe的Id获取子页面的dom,然后通过内置属性contentWindow取得子窗口的window对象,此方法兼容各个浏览器 document.getElementById('iframe_Id').contentWindow // contentWindow 不能省略 (2)通过iframe的name直接获取子窗口的window对象 iframe_Name.window    //window可以省略 (3)通过win…
一. postMessage window.postMessage()方法安全地启用Window对象之间的跨源通信:例如,在页面和它产生的弹出窗口之间,或者在页面和嵌入其中的iframe之间. 二.语法 otherWindow.postMessage(message, targetOrigin, [transfer]); otherWindow:是接收对象的窗体引用,例如:子窗体(iframe)对父级窗体的引用 "window.parent" 或者其他Iframe的引用 “Window…
http://www.w3school.com.cn/tags/tag_iframe.asp father.html <!DOCTYPE html> <html> <head> <script type="text/javascript"> function ff(msg) { alert(msg); } function test() { // 只能通过iframe名称获取子页面,不能通过id var div = window.fram…
当一个页面使用了iframe作为嵌套时,如何想要将父页面的数据传给iframe子页面,那iframe所指向的呢个子页面是怎么获取呢,又或者子页面的数据要给父页面使用,那么父页面又如何获取子页面的数据呢?下面根据这种情况作了一个简单的demo案例: 父页面是parentPage.html,子页面是childPage.html. 1.情况一:父页面获取子页面传入的数据(子页面给父页面传值) 父页面: //获取子页面传入的数据 function GetChildValue(obj){ document…
1. showModalDialog参数说明 window.showModalDialog(URL, ARGS,Features)(在父窗口中调用打开新的窗口) URL          --  必选参数,类型:字符串.用来指定对话框要显示的文档的URL.ARGS  -- 可选参数,类型:变体.向窗口中传递参数.在子窗口中使用window.dialogArguments来取得传递进来的参数. Features -- 可选参数,类型:字符串.设置打开窗口的外观属性(height,width等) F…
iframe子页面与父页面通信根据iframe中src属性是同域链接还是跨域链接,通信方式也不同. 一.同域下父子页面的通信 父页面parent.html <html> <head> <script type="text/javascript"> function say(){ alert("parent.html"); } function callChild(){ myFrame.window.say(); myFrame.w…
注意事项 一 . 页面加载顺序:一般先加载完父页面才会去加载子页面,所以:必须要确保在iframe加载完成后再进行操作,如果iframe还未加载完成就开始调用里面的方法或变量,会产生错误.判断iframe是否加载完成有两种方法: 1. iframe上用onload事件 2. 用document.readyState=="complete"来判断 <iframe name="myFrame" src="2.html"></ifra…
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="Keywords" content=""> <meta name="Description" content="&…
同域下父子页面的通信 父页面: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function say(){ alert("调用父页面方法成功"); } function…