window.location.close 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: html close window button

<button type="button" onclick="javascript:window.close()"> Name </button>

Example 3: window.open javascript auto close

<script type="text/javascript">
function allOn(){
    var win = window.open('http://www.yahoo.com','windowname','width=1,height=1,left=5,top=3');
    setTimeout(function() { win.close();}, 3000);
}
</script>