0

i have used following script for clearing the session on browser close button in C#,asp.net but the event is raised when refresh button raised also How to resolve this please give responce as soon as poossible.

<script type="text/javascript">
       var sessionTimeout = <%= Session.Timeout %>;
        var Content="load";

        var lefttime=sessionTimeout;
        var interval;
        interval = setInterval('change()',60000);

        function change()
        {

           lefttime--;
           if (lefttime <= 1) {
           PageMethods.logOut();
           }

        }
     function divClick1() {
             Content="div";

            }

    window.addEventListener("beforeunload", function (e) {
     if(Content=="load")
      returnValue = PageMethods.logOut(); 

    });

  </script>

thank you

veni
  • 1
  • 2
  • 1
    possible duplicate of [javascript detect browser close tab/close browser](http://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser) – Nick Coad Jul 31 '15 at 04:34
  • check this link http://stackoverflow.com/questions/181189/to-detect-if-the-user-is-closing-the-ie-browser-apart-from-onunload-event-as-it – madhu Jul 31 '15 at 04:40
  • Thanks for reply but those links not solved my problem still script is working when refresh button also its calling that method – veni Jul 31 '15 at 05:13
  • if the page is opened in multi tabs , someone close one of these tabs , it will trigger the logout? I think you can set the session expiration time to a smaller value, then keep the session available by ajax request. ps: the the cookie sessionID stored is a session cookie by default ,so when close all tabs/browser, it will be deleted automatically and logout – aspark Jul 31 '15 at 07:30

0 Answers0