我有這個HTML代碼:<html> <head> <script type="text/javascript"> function GetDoc(x) { return x.document || x.contentDocument || x.contentWindow.document; } function DoStuff() { var fr = document.all["myframe"]; while(fr.ariaBusy) { } var doc = GetDoc(fr); if (doc == document) alert("Bad"); else alert("Good"); } </script> </head> <body> <iframe id="myframe" src="http://example.com" width="100%" height="100%" onload="DoStuff()"></iframe> </body></html>問題是我收到消息“錯誤”。這意味著iframe的文檔未正確獲取,而GetDoc函數實際返回的是父文檔。如果您告訴我在哪里犯錯,我將不勝感激。(我想將文檔托管在IFrame中。)謝謝。
從主文檔中的JavaScript獲取IFrame的文檔
婷婷同學_
2019-11-30 10:23:05