We can open popup windows with the
For example, we can write:
const monkeyWindow = window.open();
To add some content to the window, we can write:
const monkeyWindow = window.open(); const windowContent = `<h1>hello world</h1>`; monkeyWindow.document.write(windowContent);
document.write on the
monkeyWindow to show the content.
Also, we can show the content of a URL with the
const monkeyWindow = window.open(); monkeyWindow.location.assign("https://www.google.com");
Now we should see Google displayed in the new window.
We can also write:
const monkeyWindow = window.open(); monkeyWindow.location.href = "https://www.google.com";
to do the same thing.
To close a window, we can write:
const monkeyWindow = window.open(); monkeyWindow.location.href = "https://www.google.com"; monkeyWindow.close();