Iframe易于嵌套及管理页面,但常常遇到跨域、父子页面访问问题,对于子页面访问父页面能够兼容性地经过window.Top或window.Parent或window.frameElement等操做,但对于标题中四个对象,一直没有完整测试过,故买个苦力,分享给你们。html
contentWindow contentDocument document frameschrome
Firefox 11 √ √ × √跨域
Opera 11 √ √ × √浏览器
Chrome 15安全
/360 极速 5.2 √ × × √测试
Safari 5.1 √ √ × √spa
Maxthon 3.3 √ √ × √htm
IE6 √ × √ √对象
IE7 √ × √ √ip
IE8/360安全 √ √ √ √
IE9 √ √ √ √
IE10 √ √ × √
搜狗/QQ/
百度IE √ × √ √
百度极速 √ √ × √
结论:
1. 就浏览器而言(横向),IE8/IE9/360安全浏览器所有支持;
2. 就属性而言(纵向),contentWindow和frames全部浏览器都支持,其次是contentDocument,document支持性最差;
3. 因为iframe常常涉及跨域,本地测试(即未发布)环境中,chrome/360极速/IE6/IE9对于contentWindow.document属性是deny状态,缘由是Unsafe JavaScript attempt to access frame with URL file:///***.html from frame with URL file:///***.html Domains, protocols and ports must match。IE9本地环境下对于contentDocument也是deny的。