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

Posted on In QA

How 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

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *