Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Javascript | Window Open() & Window Close Method

  • Last Updated : 26 Jul, 2019 This method is used to open the web pages into new window.
Syntax:, 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 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.

This method is used to close the window which are opened by method.


Parameters: This method does not contains any parameter.

Return Value: This method does not return any value.

Below example illustrates the and window.close() method in jQuery:


<!DOCTYPE html>
      window open and close method
        var Window;
        // Function that open the new Window
        function windowOpen() {
            Window =
                "_blank", "width=400, height=450");
        // function that Closes the open Window
        function windowClose() {
    <button onclick="windowOpen()">
      Open GeeksforGeeks
    <button onclick="windowClose()">
      Close GeeksforGeeks

Output: If click on open GeeksforGeeks button then 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

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!