。問題是它阻止了其他腳本的運行。 Firefox,Chrome或任何體面的瀏覽器都會繼續運行其餘的腳本。 我需要在運行代碼之前抑制錯誤或確保parent.parent存在。Internet Explorer對象不支持我有了這個代碼的iframe拋出一個錯誤,此屬性或方法
在php中,我會寫一些像if(!empty(parent.parent) { //do stuff with parent.parent }
來檢查對象是否存在。
是,在嵌套的iframe是醜陋O_O
。問題是它阻止了其他腳本的運行。 Firefox,Chrome或任何體面的瀏覽器都會繼續運行其餘的腳本。 我需要在運行代碼之前抑制錯誤或確保parent.parent存在。Internet Explorer對象不支持我有了這個代碼的iframe拋出一個錯誤,此屬性或方法
在php中,我會寫一些像if(!empty(parent.parent) { //do stuff with parent.parent }
來檢查對象是否存在。
是,在嵌套的iframe是醜陋O_O
你可以在try/catch塊包起來:
function parentIframeResize() {
try {
var height = getParam('height');
parent.parent.resizeIframe(height);
} catch(err) {
// do something to recover from the problem, or nothing to suppress it
}
}
嘗試,
if (parent.parent && parent.parent.resizeIframe) {
// parent.parent exists and supports resizeIframe
parent.parent.resizeIframe(height);
}
這應該工作和停止的錯誤。
您可以通過,如果(parent.parent && parent.parent.resizeIframe)在一個表達有一點簡化此。 – thomasrutter 2010-07-26 02:25:36
比try/catch更優雅,尤其是thomasrutter的建議。 +1兩者 – 2010-07-26 05:03:41