How to open a URL in a new window in JavaScript?
Posted on In QAHow to open a URL in a new window in JavaScript?
For example, to open a new window to browse “http://www.systutorials.com“.
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