javascript关于Iframe父窗口和子窗口交互
来源:互联网 发布:红太阳大数据产业中心 编辑:程序博客网 时间:2024/06/05 02:27
//兼容IE、Firefox的iframe DOM获取函数function getIFrameDOM(id){return document.getElementById(id).contentDocument || document.frames[id].document;}
parent.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><div id="pHello" style="margin:10px auto;width:360px;height:30px;">此处可通过iframeB的JavaScript函数,来替换哦~</div><iframe id="wIframeA" name="myiframeA" src="a.html" scrolling="no" frameborder="1"></iframe><iframe id="wIframeB" name="myiframeB" src="b.html" scrolling="no" frameborder="1"></iframe><div style="margin:10px auto;width:300px;height:40px;"><input type="button" value="父窗口操作iframeA" onclick="iframeA();" style="width:150px;float:left;"/><input type="button" value="父窗口操作iframeB" onclick="iframeB();" style="width:150px;float:left;"/></div><script type="text/javascript">function iframeA(){var a = getIFrameDOM("wIframeA");a.getElementById('hello_a').style.background = "red";}function iframeB(){var a = getIFrameDOM("wIframeB");a.getElementById('hello_b').style.background = "green";}function getIFrameDOM(id){return document.getElementById(id).contentDocument || document.frames[id].document;}</script></body></html>
a.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><div id="hello_a">Hello a.html</div><script></script></body></html>
b.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><div id="hello_b">Hello b.html</div><input type="button" value="子窗口操作父窗口" onclick="parentIframe();" style="width:150px;float:left;"/><input type="button" value="子窗口操作iframeA" onclick="iframeA();" style="width:150px;float:left;"/><script type="text/javascript">function iframeA(){var a = parent.getIFrameDOM("wIframeA");a.getElementById('hello_a').style.background = "blue";}function parentIframe(){parent.document.getElementById("pHello").innerHTML = "<p style='background:#000;color:#fff;font-size:15px;'>O(∩_∩)O哈哈~用子窗口B就可以替换你!不服吗?</p>";}</script></body></html>
注意:
--------------------------------------------
在firefox下,iframe背景默认的是透明的,在IE下默认不是透明的,
我们可以使用allowTransparency='true' 来设置IE下的iframe为透明,
另外我们使用scrolling ='no' frameborder='0'分别来实现iframe页面没有滚动条,边框宽度。
动态将Iframe背景置为透明
iframeObj.allowTransparency = true;
- javascript关于Iframe父窗口和子窗口交互
- 关于子窗口刷新父窗口(iframe)的问题?
- iframe 父窗口和子窗口的调用方法
- iframe 父窗口和子窗口相互的调用方法
- iframe 父窗口和子窗口的调用方法
- iframe 父窗口和子窗口相互调用
- iframe 父窗口和子窗口的调用方法
- iframe 父窗口和子窗口方法互调
- iframe 父窗口和子窗口相互的调用方法
- iframe父窗口和子窗口的调用方法
- iframe父窗口和子窗口的相互取值
- iframe 父窗口和子窗口相互的调用方法
- 父窗口和iframe子窗口之间相互传递…
- 父窗口和子窗口的数据交互
- 父窗口和子窗口之间的交互
- 父窗口调用iframe子窗口方法
- iframe 父窗口掉子窗口方法。
- Iframe父窗口与子窗口
- oracle11g jdbc配置全攻略 ORA-12505
- Action的属性依赖注入详解
- 安卓游戏开发之【扎金花游戏】(四)
- [转]js中escape,encodeURI,encodeURIComponent三个函数的区别
- Java获取Google天气预报---储存到本地
- javascript关于Iframe父窗口和子窗口交互
- Android解析XML三种方式(PULL、SAX、DOM)
- Unix网络编程(卷二)源码编译报错解决
- 水仙花数
- 牛腩新闻发布系统总结
- linux 内核移植和根文件系统的制作
- AndroidManifest.xml文件综合详解
- 大小端字节序的判断
- 关于 a-- 和 --a