create eventlistener to close webpage js

JavaScript
const result = document.querySelector('.result');

const dialog = document.querySelector('.example-dialog');
dialog.addEventListener('close', (event) => {
    result.textContent = 'dialog was closed';
});

const openDialog = document.querySelector('.open-dialog');
openDialog.addEventListener('click', () => {
  if (typeof dialog.showModal === 'function') {
      dialog.showModal();
      result.textContent = '';
  } else {
      result.textContent = 'The dialog API is not supported by this browser';
  }
});

const closeButton = document.querySelector('.close');
closeButton.addEventListener('click', () => {
    dialog.close();
});
function openWin()
{

  myWindow = window.open("", "myWindow", "width=200, height=100");   // Opens a new window

}



function closeWin()
{

  myWindow.close();   // Closes the new window

} 
Source

Also in JavaScript: