HTML5 跨浏览器 iframe 帖子消息——子级到父级?
父对象从子对象提供对主窗口的引用。
以下为父代码。下面的指令触发 iFrame 每隔 3 秒向父窗口发送一条消息。无需主窗口的初始消息!
var a= window.addEventListener ? "addEventListener" : "attachEvent";// here a is the event method var b= window[a];// here b is the eventer var c= a== "attachEvent" ? "onmessage" : "message";// here c is the message event // Listen to message from child window b (c,function(e) { var d= e.message ? "message" : "data";// here d is the key var f= e[d];//here f is data },false);
广告宣传