iframe 跟ie,firefox,chrome 的爱恨情仇
来源:互联网 发布:网络教育春季报名 编辑:程序博客网 时间:2024/04/20 22:21
开幕场景
inner.html
对白一:chrome我有我的要求
首先把上面的两个html放在非host上,也就是用file:///{path}/iframe.html来访问,当然inner.html也要和它在平级目录,你发现javascript不工作,
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
但当他们放到一个站点内它又满血复活.
原因: Chrome会把本地iframe 也当成是跨域
对白二: ie我会72变
在ie6和ie7中对contentDocument不支持,还好ie的版本都支持contentWindow,frames 因此需要下面的代码:
但ie10(我的电脑只有ie10)和firefox都可以在用file:///{path}/iframe.html来访问。另外如果把上面的js换成
iframe.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" /><title>无标题文档</title></head><body><a href="javascript:;" onclick="return getIframeDocument()">get iframe input value</a> <div class="content" id="content"> <iframe scrolling="no" frameborder="0" src="inner.html" class="comnet" name="comnet" id="comnet"></iframe> </div> <script type="text/javascript">function getIframeDocument(){var iframe = document.getElementById('comnet');var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;if(iframeDocument){alert(iframeDocument.getElementById('first').value);}else{alert("oops!");}return false;}window.onload=function(){//取iframevar iframe = document.getElementById('comnet');var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;if(iframeDocument){alert(iframeDocument.getElementById('first').value);}else{alert("oops!");}};</script></body></html>
inner.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" /><title>this is iframe document</title></head><body><div id="mainright">ddd</div><div><input type="text" id="first" value="ccc"/></div></body></html>
对白一:chrome我有我的要求
首先把上面的两个html放在非host上,也就是用file:///{path}/iframe.html来访问,当然inner.html也要和它在平级目录,你发现javascript不工作,
Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
但当他们放到一个站点内它又满血复活.
原因: Chrome会把本地iframe 也当成是跨域
对白二: ie我会72变
在ie6和ie7中对contentDocument不支持,还好ie的版本都支持contentWindow,frames 因此需要下面的代码:
iframe.contentDocument || iframe.contentWindow.document
但ie10(我的电脑只有ie10)和firefox都可以在用file:///{path}/iframe.html来访问。另外如果把上面的js换成
var iframe = window.frames["comnet"];if(iframe.document){alert(iframe.document.getElementById('first').value);}else{alert("oops!");}
对白三: firefox我忠贞如一
上面的ie10问题,chrome问题,在firefox上都没问题
参考连接:各浏览器Iframe对contentWindow、contentDocument、document及frames属性测试
- iframe 跟ie,firefox,chrome 的爱恨情仇
- iframe框架取值兼容ie/firefox/chrome的写法
- Firefox、Chrome跟IE的差别:对以"/>"结尾的标签的不同处理效果
- IE FireFox iframe操作的小结
- virtual iframe. IE + FireFox
- IE和Chrome、FireFox的ContentType问题!
- IE、FireFox、Chrome浏览器的全屏实现
- webdriver的初步学习(IE,Chrome,Firefox)
- 兼容IE-FireFox-Chrome的背景音乐播放
- 兼容IE-FireFox-Chrome的背景音乐播放
- IE、Firefox、Chrome比较
- 解决IE,Firefox,chrome,safari浏览器中iframe显示高度自适应问题
- 解决IE,Firefox,chrome,safari浏览器中iframe显示高度自适应问题
- IE和Firefox中Iframe的互操作问题
- 兼容FireFox和IE的iframe自适应高度js函数
- 访问iframe里面的javascript函数、对象,兼容IE、Firefox
- 适用于IE和Firefox的iframe自适应高度JS代码
- 适用于IE和Firefox的iframe自适应高度JS代码
- spring注入方式之construct方式注入
- uip协议栈分析
- [每日一题] OCP1z0-047 :2013-08-22 正则表达式---[^Ale|ax.r$]'....................................92
- struts2 Error filterStart问题
- nfs启动出现网络断开Try to bring eth0 interface up....../etc/init.d/ifconfig-eth0: line 6: grep: not found
- iframe 跟ie,firefox,chrome 的爱恨情仇
- 程序员最重要的技能
- [leetcode] Palindrome Partitioning II
- uva 10057 A mid-summer night's dream.(检索)
- 几种开放源码的TCPIP协议栈概述--LwIP,uIP,TinyTcp和uC/IP
- POJ 2063 Investment 完全背包
- WIN7自带的虚拟键盘
- Java程序栈信息文件中的秘密(五)
- x86架构下函数堆栈恢复方法