JavaScript window.open() Method

You are Here:

JavaScript window.open() Method

The window.open() method opens a new browser window, or a new tab, depending on your browser settings and the specified resource is loaded into its browsing context.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open Homepage</button> <script> function myOpen(){ window.open("https://wikimass.com"); } </script> </body> </html>

Syntax

window.open(url, windowName, Specification)

Parameter Values

ValueTypeExplanation
urlRequiredA string specifies the URL of the resource to be loaded.
windowNameOptionalA strong specifying the name of the browsing context into which to load the specified resource.
SpecificationOptionalA string containing a comma-separated list of window features given with their corresponding values in the form "name=value, name1=value1".

Open Window with Options

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open Window</button> <script> var myWindow; function myOpen(){ myWindow = window.open("","myWindow","width=300, height=300"); } </script> </body> </html>

Open Window with Specified Target

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open Homepage</button> <button onclick="myOpenSelf()">Open Homepage (_self)</button> <button onclick="myOpenOption()">Open Homepage (options)</button> <script> function myOpen(){ //'_blank' is the default behavior window.open("https://wikimass.com", "_blank"); } function myOpenSelf(){ window.open("https://wikimass.com", "_self"); } function myOpenOption(){ window.open("https://wikimass.com", "_blank", "toolbar=no,scrollbars=yes,resizable=yes,top=50,left=50,width=400,height=500"); } </script> </body> </html>

Open Multiple Windows

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myOpen()">Open Websites</button> <script> function myOpen(){ window.open("https://wikimass.com"); window.open("https://www.2braces.com"); } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author