1

In Chrome and Edge this simple example results shows a "Click Me!" button that opens a new tab.

function test() {
  var myWindow = window.open("", "_newtab");
  myWindow.document.write("hello world");
}
<button onclick="test()">
    Click Me!
</button>

The issue is that the new tab appears to be still loading after it is displayed.

enter image description here

Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
estimpson
  • 113
  • 1
  • 6
  • you can't actually run this code in stack overflow because window.open() returns null in this environment – estimpson Nov 10 '20 at 19:41

1 Answers1

2

document.write implicitly calls document.open if the document isn't open for writing.

While it remains open for writing, the loading spinner will tick.

You need to explicitly close the document for writing to stop that:

myWindow.document.close();
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335