0

When I add another window using var w = window.open("", "_blank"); , it shows as URL about:blank and I can write to its body with no problem. but at the end, looking at the sources it only has and there is nothing to work with.

If instead I use existing HTML file,var w = window.open("{some path}/Empy.html", "_blank"); All the $(w.document.body).append(... commands write somewhere else not inside the opened file.
Is there a promise I can use, to start writing to it only after the existing file finished rendering?

Ofer Gal
  • 707
  • 1
  • 10
  • 32

1 Answers1

0

this will work in IE to, extended from this answer

function openindex(){ 
    OpenWindow = window.open("http://www.htmlgoodies.com/beyond/javascript/article.php/3471221", "_blank");

    myFunction = function(){

        alert("hi")

        window.document.write("<TITLE>Title Goes Here</TITLE>")
        window.document.write("<BODY BGCOLOR=pink>")
        window.document.write("<h1>Hello!</h1>")
        window.document.write("This text will appear in the window!")
        window.document.write("</BODY>")
        window.document.write("</HTML>")
        window.document.close()

    }

    OpenWindow[OpenWindow.addEventListener ? 'addEventListener' : 'attachEvent'](
      (OpenWindow.attachEvent ? 'on' : '') + 'load', myFunction, false
    );

}

in my example i overwrite the entire page since i dont know if it has jQuery nor i tried to target specific element, but that is the way to go.

p.s. the url is just random

bresleveloper
  • 5,940
  • 3
  • 33
  • 47