estimpson
estimpson

Reputation: 113

JavaScript problem displaying a new window from client-side code

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

Upvotes: 1

Views: 29

Answers (1)

Quentin
Quentin

Reputation: 943510

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();

Upvotes: 2

Related Questions