浏览器主页、iframe、子窗口的互相操作
来源:互联网 发布:手机淘宝怎么取消订单 编辑:程序博客网 时间:2024/06/05 03:46
主页操作iframe:
var ifs = document.getElementById('iframeID').contentWindow.document; \\获取到iframe的document对象document.getElementById('iframeID').contentWindow.jsMethod(); \\调用iframe的JS方法ifs.getElementById('elementID').onclick(function(){alert('function binding in main page!');}); \\在主页中为iframe绑定主页的方法
子iframe操作主页:
var pp = parent.document; \\获取主页的documentparent.jsMethod(); \\调用主页JS方法pp.getElementById('elementID').onclick(function(){alert('function binding in main page!');}); \\在iframe中为主页绑定iframe中的方法
主窗口操作子窗口:
var nw = window.open("about:blank"); var nd = nw.document; \\获取子窗口的documentnw.jsMethod(); \\调用子窗口JS方法
子窗口中操作主窗口:
var od = opener.document; \\获取主窗口的documentopener.showJS(); \\调用主窗口的js
样例代码:
<html><head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script><script>var nw;var injectHtml = '<hr><div><p>inject success</p>\<div>iframe test<input type="button" value="test parent DOM" onclick="parent.document.getElementById(\'showtext\').innerHTML=\'parent element changed!\'" >\<input type="button" value="test parent JS" onclick="parent.showJS();" ></div>\<div>new window test<input type="button" value="test parent DOM" onclick="opener.document.getElementById(\'showtext\').innerHTML=\'parent element changed!\'" >\<input type="button" value="test parent JS" onclick="opener.showJS();" ></div>\<div>method binding<input type="button" value="open parent new window" id="bindingmethod" >\<input type="button" value="show iframe" id="binding2"></div>\</div>';$(document).ready(function(){});function injectWithIframe(html){if (nw) {nw.close()};var iframe = '<iframe src="about:blank" frameborder="0" name="FirebugUI" id="FirebugUI" style="border: 0px; visibility: visible; z-index: 2147483647; position: fixed; width: 100%; left: 0px; bottom: 0px; height: 241px; display: block;"></iframe>';$("#iframediv").append(iframe);var ifs = document.getElementById('FirebugUI').contentWindow.document;$(ifs.body).html(html);$('#bindingmethod', ifs.body).click(this.opennewwithhtml);}function opennewwithhtml(){openInNewWindow(injectHtml);}function openInNewWindow(html){$('#iframediv').empty();nw = window.open("about:blank");$(nw.document.body).html(html);$('#binding2', nw.document.body).click(this.showIframe);}function showIframe(){injectWithIframe(injectHtml)}function showJS(){$('#showtext').text('parent JS called!');}</script></head><body><div><input type="button" value="inject iframe" onclick="javascript:injectWithIframe(injectHtml)" ><input type="button" value="inject new window" onclick="javascript:openInNewWindow(injectHtml)" ></div><div id="showtext"></div><div id="iframediv"></div></body></html>
0 0
- 浏览器主页、iframe、子窗口的互相操作
- 主页面与iframe的互相访问
- 主页面与iframe子页面互相传值
- Jquery取得iframe子父元素互相操作的方法
- html窗口与其iframe子窗口之间的方法操作
- IFrame子窗口JS方法互相调用和传参
- IFrame子窗口JS方法互相调用和传参
- js中iframe的子父页面互相操作的方法
- 转 iframe 子 父类窗口操作
- 转 iframe 子 父类窗口操作
- iframe子页面与父页面之间互相操作的方法。
- js 页面使用iframe 父页面子页面互相操作
- Iframe 父窗口 外面 调用 iframe子窗口的function
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
- 总结JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
- MongoDB query 用法
- 对于除法之后再取余数的处理:
- Python装饰器学习
- javascript继承对象冒充方式
- Pydev在Eclipse上的安装及配置
- 浏览器主页、iframe、子窗口的互相操作
- Linux---系统参数,监控小结(1)
- Spark0.9分布式运行MLlib的线性回归算法
- 完整版android视频播放器
- Python源码剖析----第二章
- 【递推】【DP】-HDU-2064-汉诺塔③
- 日期控件
- Android轻量级orm框架——KKORM
- Eclipse中为Android应用添加jar包