NOTE: Most probably, you can not close a tab with JS for security issue. You can only close a tab with JS what is opened with JS.
You can use JQuery. Do not submit the form. Send Ajax request to server with onclick event. When dataType of Ajax request is 'script', browser will execute response body as JS.
note: save files (index.php and logout.php) in same directory.
in index.html :
<html>
<head>
<title>Ajax Logout</title>
<style>
.logout-button {
background:#00aaee;
display:inline-block;
padding: 5px 10px;
cursor: pointer;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
<div class="logout-button">logout</div>
<script type="text/javascript">
function closeTab(){
confirm("test");
//your code here
}
$('.logout-button').on('click', function(){
$.ajax({
url: ('logout.php'),
type: 'POST',
dataType: 'script'
});
});
</script>
</body>
</html>
in logout.php :
<?php
session_start();
session_unset();
session_destroy();
echo "closeTab();";
?>