LearnFast.Ninja

JavaScript close window

How to close a window using JavaScript function. You can close the window in few ways but the function you call to is the window close function. This close function tell the window to be closed.

Main idea:
window.close()

Working example code: In this example we trigger the function on the click event of the div element.

<!DOCTYPE html>

<html>

<head>

    <title>My window</title>

</head>

<body>

   <div onclick="window.close()">Close this window</div>

</body>

</html>


Tags

javascript

close window