Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript window.close() Method

JavaScript window.close() Method

JavaScript window.close() method, is used for closing a certain window or tab of the browser which was previously opened by the window.open() method.

Syntax:

window.close();

Parameters: This method does not accept any parameters.

Example: In this example, at first we will use the window.open() method to open a new window, assign its value to a temporary variable, and use that variable with the window.close() method to close that page.

HTML




<h2>Window.close() object GFG</h2>
<button class="btn open">Open</button>
<button class="btn close">Close</button>
<script>
    var newPage = document.querySelector('.open')
        .addEventListener('click', function () {
     
            newWindow =
                window.open('https://www.geeksforgeeks.org/',
                '_blank',
                'width=400,height=400 top=100,left=800');
    });
     
    document.querySelector('.close')
    .addEventListener('click', function () {
        newWindow.close();
    });
</script>


Output:

 

Supported Browsers:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above 
  • Opera 3 and above
  • Safari 1 and above

JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.

HTML is the foundation of web pages and is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS