javascript close current window 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: how to close tab by javascript
<button onclick="window.close();">Exit</button>
function closeWin() {
myWindow.close();
}
function openWin() {
myWindow = window.open("", "myWindow", "width=200, height=100");
}