javascript close window – How to close window using JavaScript?

javascript close window – The close() method closes the current window. also JavaScript provides an in-built function named close() to close the browser window.

javascript close window

window.close();//closes the current browser tab. To close a window or tab that was opened using JavaScript. Windows are opened with window.open(); and Windows are closed with window.close();

How to Close a Window with JavaScript?

javascript close current window
closes the current browser tab

window.close();

javascript close window Example

index.html

<!DOCTYPE html>
<html>
<body>

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

<script>
var livePayment;

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

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

</body>
</html>

Example : close a browser window with HTML code

<input type="button" value="Exit" onclick="self.close()">

<script language="javascript" type="text/javascript">
function windowClose() {
window.open('','_parent','');
window.close();
}
</script>

<input type="button" value="Exit" onclick="windowClose();">

Don’t Miss : How To Open URL In New Tab Using JavaScript?

I hope you get an idea about javascript close window.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.