iframe contentDocument und contentWindow ist null

Ich versuche, Zugriff auf iframe-contentDocument und contentWindow in folgenden code. Aber Sie sind beide null.

    var iframe = document.createElement('iframe');
    this.get__domElement$i().appendChild(iframe);
    if (iframe.contentDocument) {
         iframe.contentDocument.write("Hello");
     }
    else if (iframe.contentWindow) {
         iframe.contentWindow.document.body.innerHTML = "Hello";
     }

Kann mir jemand sagen, was ist falsch in diesem? Dank

Wenn ich Dokument.Körper.AppendChild(iframe), dann contentDocument und contentWindow sind nicht null.

Kann mir jemand sagen, was falsch ist, wenn ich, fügen Sie den iframe-Element div?

Vielen Dank.

Schreibe einen Kommentar