作家
登录

Webkit的跨域安全问题说明

作者: 来源:www.28hudong.com 2013-03-30 00:44:12 阅读 我要评论

这里有个简单的测试页面:IE、火狐弹出"hello world",而chrome,safari,opera毫无反应。 以下是小段测试代码(刻意修改domain,让父页面和子页面为不同域页面): 1.父页面代码: 复制代码 代码如下: <script> document.domain = "nunumick.me"; function doTest(){ alert('hello world'); } </script> <iframe src="http://www.nunumick.me/lab/x-domain/webkit-test.html"> </iframe> 2.子页面代码: 复制代码 代码如下: <script> try{ top.name; }catch(e){ document.domain = 'nunumick.me'; top.doTest(); } </script> 以上代码目的是尝试在访问异常时动态修改domain达到顺利访问,但webkit内核浏览器粗暴地报错而非抛出可截获的异常,其他浏览器均如期运行。 chrome错误信息: 据了解,采用此类try catch方式做安全可行性判断的并不只是个别现象,如DOJO复制代码 代码如下: try{ //see if we can access the iframe's location //without a permission denied error var iframeSearch = _getSegment(iframeLoc.href, "?"); //good, the iframe is same origin (no thrown exception) if(document.title != docTitle){ //sync title of main window with title of iframe. docTitle = this.iframe.document.title = document.title; } }catch(e){ //permission denied - server cannot be reached. ifrOffline = true; console.error("dojo.hash: Error adding history entry. Server unreachable."); } 再如FCKeditor复制代码 代码如下: try{ if ( (/fcksource=true/i).test( window.top.location.search ) ) sFile = 'fckeditor.original.html' ; } catch (e) { /* Ignore it. Much probably we are insi de a FRAME where the "top" is in another domain (security error). */ } 还有很多网友的反馈:chrome bug report 以上代码在chrome,safari,opera均不适用。翻了一些资料,记录在此:1.html5 security location2.webkit dev lists从webkit开发人员的讨论消息中看到,他们承认这个问题但并不情愿去改正,holly shit!

  推荐阅读

  JQuery与JSon实现的无刷新分页代码

如图 而无刷新分页可以解决这个问题,上面播放着视频,下面我点下一页看着评论,现在大部分的网站都是无刷新分页。 源码如下(我是采用一页显示10条记录): 需要四个文件 一个实体类文件 CategoryInfoModel.cs >>>详细阅读


本文标题:Webkit的跨域安全问题说明

地址:http://www.17bianji.com/kaifa2/JS/24171.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)