Holen Sie sich das Dokument von IFrame aus JavaScript im Hauptdokument

Ich habe diesen HTML-Code:

<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>

Das Problem ist, dass ich die Meldung "Bad" bekomme. Dies bedeutet, dass das iframe-Dokument nicht korrekt abgerufen wird und dass das übergeordnete Dokument von der GetDoc-Funktion zurückgegeben wird.

Ich wäre dankbar, wenn du mir sagen würdest, wo ich meinen Fehler mache. (Ich möchte ein Dokument in IFrame hosten lassen.)

Vielen Dank

Antworten auf die Frage(4)

Ihre Antwort auf die Frage