coding180 icon
Coding180
JavaScript - close window (window.close)

JavaScript - close window (window.close)

Home > Tutorials > JavaScript > Common Interaction Methods


close() closes the window

usage:

window.close(); //Close this window

or

<window object>.close(); //Close the specified window

For example: close the newly created window.

<script type="text/javascript">
//store the newly opened window object in the variable mywin
   var mywin=window.open('http://www.google.com'); 
   mywin. close();
</script>

Note: The above code closes the window while opening a new window, and the opened window cannot be seen.

Task - Exercise - 15

In 7th line use close() to directly close the opened web page.

Task Code

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS close() - coding180.com </title>
  <script type="text/javascript">
     var mywin=window.open("http://coding180.com");
 
  </script>
</head>
<body>
</body>
</html>

 


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel