0

I want to detect whether page is refresh or closed.On close, I am clearing session. But my session getting clear on browser refresh also. I have searched but not found any solution.

I have used various method to solve:-

Method 1(this work but session out on refresh also.)

function HandleOnClose(event) /*called on onbeforeunload on body*/ {
    if (event.clientY < 0) {
        var request = GetRequest();
        Urladd = "logout url goes here" //logiut URL work fine 
        request.open("POST", Urladd, false);
        request.send();
    }
}

function GetRequest() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

Method 2: How to know whether refresh button or browser back button is clicked in firefox

Method 3:Identifying Between Refresh And Close Browser Actions

Jose Rojas
  • 3,490
  • 3
  • 26
  • 40
Mike Phils
  • 3,475
  • 5
  • 24
  • 45
  • I don't think you can distinguish between the two without writing a browser plug-in/extension. – Scott Marcus Mar 02 '18 at 17:23
  • There is no way to know. Have a nice day. :) – epascarello Mar 02 '18 at 17:25
  • Then how in the world this thing is get handled???There could be some way... – Mike Phils Mar 02 '18 at 17:33
  • @ScottMarcus any example or reference. – Mike Phils Mar 02 '18 at 17:39
  • No. I have no experience with plug-ins. I just know you can't do it with normal page code. – Scott Marcus Mar 02 '18 at 17:39
  • May I suggest - Rather than tell use what you want to _**do**_, tell us what you would like to accomplish. I do believe there is a use case with a solution here, but not in terms you've stated. Let's start with "Close" vs. "Refresh"? The basis of this question stems from the idea that, to the browser, they are exactly the same thing. How would you define these terms ("Close" vs. "Refresh")? – Randy Casburn Mar 02 '18 at 17:48
  • over here closed is clicking close button of browser, and refresh means refresh page of browser. – Mike Phils Mar 02 '18 at 18:18

0 Answers0