根據(jù) DOM-2 中的描述,HTMLFrameElement 和 HTMLIFrameElement 都沒(méi)有 'document' 屬性。
關(guān)于 HTMLFrameElement 對(duì)象的詳細(xì)信息,請(qǐng)參考 DOM-2 Interface HTMLFrameElement 中的內(nèi)容。
關(guān)于 HTMLIFrameElement 對(duì)象的詳細(xì)信息,請(qǐng)參考 DOM-2 Interface HTMLIFrameElement 中的內(nèi)容。
僅 IE Opera 支持使用 HTMLFrameElement.document 和 HTMLIFrameElement.document 屬性得到框架頁(yè)的 HTMLDocument 對(duì)象。這個(gè)屬性是非標(biāo)準(zhǔn)的。
如果試圖通過(guò) HTMLFrameElement 和 HTMLIFrameElement 對(duì)象的 'document' 屬性獲得框架頁(yè)的 HTMLDocument 對(duì)象,在 FrireFox Chrome Safari 中將得到 'undefined'。
IE6 IE7 IE8 Opera |
---|
分析以下兩組測(cè)試代碼,他們分別嘗試獲取 HTMLFrameElement 和 HTMLIFrameElement 的 'document' 屬性:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script> window.onload=function(){ alert(document.getElementById("frame").document); }; </script> </head> <frameset> <frame id="frame" src="_content.html" /> </frameset> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script> window.onload=function(){ alert(document.getElementById("frame").document); }; </script> </head> <body> <frame id="frame" src="_content.html" /> </body> </html>
以上測(cè)試用例中,只有 IE6 IE7 IE8 Opera 對(duì)兩者均會(huì)得到一個(gè) HTMLDocument 對(duì)象(即框架內(nèi)頁(yè)面的 document 對(duì)象),而其他瀏覽器返回的是 'undefined'。
注:以上測(cè)試與文檔模式無(wú)關(guān)。
使用 HTMLFrameElement 或 HTMLIFrameElement 對(duì)象的 contentWindow 屬性得到該框架頁(yè)的 window 對(duì)象應(yīng)用,再訪問(wèn)其下的 document 對(duì)象。
即把上述測(cè)試代碼的 'XXX.document' 更改為 'XXX.contentWindow.document',如:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script> window.onload=function(){ alert(document.getElementById("frame").contentWindow.document); }; </script> </head> <frameset> <frame id="frame" src="_content.html" /> </frameset> </html>
如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇