js close page code example
Example 1: javascript close current tab
window.close();
Example 2: 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 3: close browser tab javascript
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.open("/folderDirectory/example.php");
</script>
</head>
</html>
$(document).ready(function(){
$("button").click(function(){
window.close();
});
});
<button style="border: none;" >Exit</button>