1// IF you use in a button
2<button onclick="window.close();">Exit</button>
3// if you use in function
4function closeWin() {
5 myWindow.close(); // Closes the new window
6}
7// But it will only work when you open a window through your code like this
8function openWin() {
9 myWindow = window.open("", "myWindow", "width=200, height=100"); // Opens a new window
10}
11// You can't close the current window that was open by browser. beacuse browser don't give permission for this
1//You are able to close a browser tab with an index.html page
2//The code below from lines 3-13 are from the index.html page, it redirects you to another page
3<!DOCTYPE html>
4<html>
5<head>
6
7 <script type="text/javascript">
8window.open("/folderDirectory/example.php");
9
10
11 </script>
12</head>
13</html>
14//The code below is from the example.php
15 $(document).ready(function(){
16 $("button").click(function(){
17 window.close();
18 });
19 });//jquery is used to make the user click the button to exit
20
21//The code below should be placed in the html body, it is a button that closes the window when the user clicks on it
22<button style="border: none;" >Exit</button>
23
24
1Writing this on 24 Dec 2020. Tried almost all the things available on google, but none of them worked in Chrome browser. window.open('','_self').close() works for IE.