Window.open() This method is used to open the web pages into new window.
Syntax:
window.open(URL, name, specs, replace)
Parameters: This method accepts four parameters as mentioned above and described below:
- URL: It is an optional parameter. It is used to set the URL of web pages which need to open. If URL is not set then window.open() method open a blank window.
- name: It is an optional parameter and used to set the window name.
- specs: It is an optional parameter and used to separate the item using comma.
- replace: It is an optional parameter and used to specify the URL URL creates a new entry or replaces the current entry in the history list. This parameter return boolean value. If this parameter returns true then URL replaces the current document in the history list and if returns false then URL creates a new entry in the history list.
Return Value: This method creates a new window.
Window.close()
This method is used to close the window which are opened by window.open() method.
Syntax:
window.close()
Parameters: This method does not contains any parameter.
Return Value: This method does not return any value.
Below example illustrates the window.open() and window.close() method in jQuery:
Example:
<!DOCTYPE html> <html> <head> <title> window open and close method </title> <script> var Window; // Function that open the new Window function windowOpen() { Window = window.open( "_blank", "width=400, height=450"); } // function that Closes the open Window function windowClose() { Window.close(); } </script> </head> <body> <button onclick="windowOpen()"> Open GeeksforGeeks </button> <button onclick="windowClose()"> Close GeeksforGeeks </button> </body> </html> |
Output: If click on open GeeksforGeeks button then geeksforgeeks.org page open in new window and if click on close GeeksforGeeks button then the geeksforgeeks.oge windows will close.

Supported Browser: The browser supported by Window Open() & Window Close Method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to close current tab in a browser window using JavaScript?
- How to open URL in a new window using JavaScript ?
- Javascript | Window Blur() and Window Focus() Method
- Open a link without clicking on it using JavaScript
- Open all persons solution links from submission page using JavaScript
- How to Open URL in New Tab using JavaScript ?
- Top 5 Free Open-Source JavaScript Frameworks For Web Developers in 2020
- 6 Most Popular and Open-Source Machine Learning JavaScript Frameworks
- Window | Window.requestAnimationFrame() Method
- How to avoid dropdown menu to close menu items on clicking inside ?
- Audio Context.close() in Web APIs
- Deesign a close button using Pure CSS
- JavaScript | clearTimeout() & clearInterval() Method
- HTML DOM indexedDB open() Method
- Web Window API | Window locationbar property
- Web Window API | Window scrollbars property
- Scoping & Hoisting in JavaScript
- JavaScript | Polyfilling & Transpiling
- JavaScript Number.MAX_VALUE & Number.MIN_VALUE Property
- How to get the image size (height & width) using JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


