How to open a URL in a new window in JavaScript?

How to open a URL in a new window in JavaScript?

For example, to open a new window to browse "http://www.systutorials.com".

asked Oct 15, 2015 by Eric Z Ma (43,500 points)

1 Answer

 
Best answer

Open the URL in a new window:

url = "http://www.systutorials.com";
window.open(url);

Some browser will open the window in a new tab depending on the configuration. If you want to force the browser to open a new window, a tip is to use code as follows.

window.open(
    url, "window name",
    "height=200,width=200,modal=yes,alwaysRaised=yes");

(it works on most browsers while the browser may still choose to ignore it)

Additionally, the "window.close()" method can close the window.

Full syntax of the "window.open()" method can be found in:

https://developer.mozilla.org/en-US/docs/Web/API/Window/open

answered Oct 15, 2015 by Eric Z Ma (43,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...