close browser in js code example

Example 1: javascript close window

<!DOCTYPE html>
<html>
<body>

<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>

<script>
var myWindow;

function openWin() {
  myWindow = window.open("", "myWindow", "width=200,height=100");
  myWindow.document.write("<p>This is 'myWindow'</p>");
}

function closeWin() {
  myWindow.close();
}
</script>

</body>
</html>

Example 2: close browser tab javascript

//You are able to close a browser tab with an index.html page
//The code below from lines 3-13 are from the index.html page, it redirects you to another page
<!DOCTYPE html>
<html>
<head>

    <script type="text/javascript">
window.open("/folderDirectory/example.php"); 


     </script>
</head>
</html>
//The code below is from the example.php
  $(document).ready(function(){
    $("button").click(function(){
      window.close();
      });
  });//jquery is used to make the user click the button to exit 

//The code below should be placed in the html body, it is a button that closes the window when the user clicks on it
<button style="border: none;" >Exit</button>