JavaScript Window close method17 Mar 2025 | 3 min read JavaScript provides an in-built function named close() to close the browser window that is opened by using window.open() method. Unlike the window.open() method, it does not contain any parameter. This window.close() method simply close the window or tab opened by the window.open() method. Remember that - You have to define a global JavaScript variable to hold the value returned by window.open() method, which will be used later by the close() method to close that opened window. SyntaxHere, window is the name of that window that is opened by the window open method. Parameters ListThis method does not have any parameters. Close the windowLet's understand with the help of an example. We will take an example to show you how to close the window or tab opened by the window.open() method. Firstly, we will open a website URL in a new window (size defined in code) using a button click and then use another button to close that opened window. ExampleIn this example, we will not specify any URL in open() method. See the below code how it will work: Copy Code Output You will get the output same as the given below. Here, clicks the Open New Window button to open a user-defined browser window. ![]() A new window will pop-up with a message, as shown below. Now, click the Close New Window button to close this pop-up window. ![]() Example 2This example will have a website URL inside the window.open() method to open a website in a new window. Then we will use close() method to close that window. Copy Code Output When you will execute the code, you will get the response as shown below: ![]() Click the Open TpointTech button to open the TpointTech tutorial website. We have specified the size (height and width) of the new pop-up window to open. ![]() If you click the Close TpointTech button, this opened window will be minimized. Browser SupportSeveral web browsers support this window function, such as:
You can run window.close() JavaScript function on these above browsers. |
In this article, we are going to discuss currying in JavaScript. Here, we will see how currying works and how it will be useful for software developers. We will also see the conversion of an existing function into the curried version. So, this article is...
4 min read
As we know, the Calculator is a portable device used in our daily life to perform various mathematical functions such as addition, subtraction, multiplication, division, root, etc. However, we have scientific or sophisticated calculators used to solve complex tasks such as trigonometry functions, degrees, exponential...
7 min read
The javascript regex is used to validate the form on the web page. We can use the validation for the numbers in the string using the javascript function. Javascript regular expression works to match, search, test, and validate the string. Syntax The following syntax uses only the numbers...
4 min read
? JavaScript is a light-weight object-oriented programming language that is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language. JavaScript enables dynamic interactivity on websites when it is applied to an HTML document. JavaScript helps the users to build modern web...
3 min read
CSV files are an essential part of computer science when you work with websites and databases. There might be some cases when the user has some data in the browser that you want to let them download this data. In that case, CSV files help...
6 min read
It's a typical hard to replace strings in JavaScript. Using the string.replace() technique to change every appearance can still be challenging. Eliminating all whitespace might be laborious when it comes to line breaks and tabs. Regex expressions are fortunately supported by JavaScript's string.replace() function. The method...
3 min read
String manipulation is easy to learn but most difficult to master of it in JavaScript. Earlier, multi-line string was not supported by JavaScript. After 2015, string literals have introduced by ES6 (ECMAScript 6) that supports multi-line string. Now, there are several ways to handle multi-line string....
5 min read
The Node Package Manager is known as npm. It serves as the Node JavaScript platform's package manager. The largest software registry in the world is referred to as Npm. Npm is a sharing and displaying tool used by open-source developers worldwide. Npm Parts Npm is made up of...
4 min read
Base64 is a binary-to-text encoding system that converts binary data into a radix-64 representation and then encodes it as an ASCII string. It is frequently used to store data in files and send data over the internet. With native JavaScript functions and modules, Base64 data...
3 min read
An Http cookie, also known as a web cookie, is a small piece of data that the server sends to the web browser. The browser may store the cookies and send them back to the server with other requests. The typical use of the cookies...
10 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India