You can use Javascript to launch an ajax request when clicking the close button.
Here it is in jQuery:
$(".close").click(function(){
$.ajax({
url: 'your-url.php',
type: 'post',
data: {},
success: function (data) {
alert('done!')
}
});
});
That way you can your page will not reload but you will be able to do some stuff server-side, e.g. insert a row in your User-Message join table.