作者tn801534 (踢恩)
看板Ajax
標題[問題] JS frame跨domain取變數時
時間Fri May 6 15:55:31 2011
http://211.20.224.10:8881/test.php
按下去GOOGLE再按下取參數即為跨網域取變數
主要的程式碼
alert("start");
if (typeof(parent.frames['bottom'])!= 'undefined' &&
typeof(parent.frames['bottom'].sysGotoLabel) != 'undefined'){
alert(parent.frames['bottom'].sysGotoLabel);
}
alert("end");
以上測試網頁在firefox 並不會去alert end會因為跨網域取JS變數,
直接出現一個亂碼的錯誤於firebug就死在那邊了
可是IE會跳過會alert出end
目前我暫時解法是用try...catch將這段包起來...程式會繼續執行
不過firebug還是會跳錯誤
請問有什麼其他比較好的方法嗎
我有想過去判斷是不是domain 可是firefox好像一拿變數就直接跳錯誤...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.20.224.10
→ mesak:js 不能跨DOMAIN 05/06 16:36
→ tn801534:恩 我知道這情況 我的意思是說要怎麼避免那段錯誤... 05/06 17:02
→ tn801534:有什麼辦法知道已經跨網域了的意思 05/06 17:03
→ frugal:window.onerror 05/12 23:06