'window.onbeforeunload....alert to restrict when refresh button click?

I have security problem that when user leave\close the window before logout, I want to show an alert message.

So that I did this:

window.onbeforeunload   = function(){  return " confirm msg";}

I get the alert, but now the problem is, if I click refresh button the default operation is to run without the alert message.

I got the answer for a keyboard but not for a mouse click. Can any one help me, with how to detect when the user clicks the refresh button?

If you have any suggestion please post...



Solution 1:[1]

Unfortunately, there is no way you can tell if the onbeforeunload event is triggered by a refresh, close, etc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xmarcos