I created a HTML file and made four sections in it, in each section I added a cross button to close tab using following code
function exitpage () {
let new_window = open(location, '_self');
// Close this window
new_window.close();
return false;
}
By adding onclick to that cross button, this code is working on 1st and 2nd section as when clicked cross button tab is closed. But this code is not working on 3rd and 4th section as code is as it is same.