最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Webkit的跨域安全問題說明

 更新時間:2011年09月13日 22:17:02   作者:  
在使用try catch處理iframe跨域產(chǎn)生的異常時,chrome和safari瀏覽器似乎不能正常運(yùn)作:他們直接拋出了錯誤而沒有拋出可供JS截獲的異常。
這里有個簡單的測試頁面:IE、火狐彈出"hello world",而chrome,safari,opera毫無反應(yīng)。
以下是小段測試代碼(刻意修改domain,讓父頁面和子頁面為不同域頁面):
1.父頁面代碼:
復(fù)制代碼 代碼如下:

<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.子頁面代碼:
復(fù)制代碼 代碼如下:

<script>
try{
top.name;
}catch(e){
document.domain = 'nunumick.me';
top.doTest();
}
</script>

以上代碼目的是嘗試在訪問異常時動態(tài)修改domain達(dá)到順利訪問,但webkit內(nèi)核瀏覽器粗暴地報(bào)錯而非拋出可截獲的異常,其他瀏覽器均如期運(yùn)行。

chrome錯誤信息:

據(jù)了解,采用此類try catch方式做安全可行性判斷的并不只是個別現(xiàn)象,如DOJO

復(fù)制代碼 代碼如下:

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
復(fù)制代碼 代碼如下:

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). */ }

還有很多網(wǎng)友的反饋:chrome bug report

以上代碼在chrome,safari,opera均不適用。翻了一些資料,記錄在此:
1.html5 security location
2.webkit dev lists
從webkit開發(fā)人員的討論消息中看到,他們承認(rèn)這個問題但并不情愿去改正,holly shit!

您可能感興趣的文章:

相關(guān)文章

最新評論

汝南县| 宕昌县| 茌平县| 南靖县| 布尔津县| 尚志市| 巴里| 元朗区| 四会市| 温宿县| 屏边| 揭西县| 佳木斯市| 甘孜县| 钟山县| 正安县| 油尖旺区| 前郭尔| 永修县| 固始县| 岳阳市| 炎陵县| 广安市| 灌阳县| 平远县| 色达县| 含山县| 星子县| 浮山县| 礼泉县| 普定县| 孙吴县| 易门县| 扬州市| 天水市| 志丹县| 邹城市| 塔河县| 化州市| 罗平县| 九龙城区|