Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
<script type="text/javascript">
        var sessionID = getQuerystring('SessionID');
        var cookieSessionID = getCookie('session');
        var validNavigation = false;

        function endSession() {
            setCookie('session', sessionID, 1);
            var cookieSU = getCookie('session');
            if (cookieSU != null) {
                getSyncData('strSessionId=' + sessionID, 'UpdateUserLogoutSession');
            }
        }

        function wireUpEvents() {
            window.onbeforeunload = function () {
                if (!validNavigation) {
                    endSession();
                }
            }


            $('document').bind('keypress', function (e) {
                if (e.keyCode == 116) {
                    validNavigation = true;
                }
            });

            $("a").bind("click", function () {
                validNavigation = true;
            });

            $("form").bind("submit", function () {
                validNavigation = true;
            });

            $("input[type=submit]").bind("click", function () {
                validNavigation = true;
            });

        }

        $(document).ready(function () {
            if (cookieSessionID == null || cookieSessionID != sessionID) {
                // Do nothing
            } else {
                if (cookieSessionID == sessionID) {
                    getData('strSessionId=' + sessionID, 'UpdateUserResetSession', function (result) {
                        if (result['Exception']) { };
                    });
                }
            }
            wireUpEvents();
        });

        function setCookie(c_name, value, exdays) {
            var exdate = new Date();
            exdate.setDate(exdate.getDate() + exdays);
            var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
            document.cookie = c_name + "=" + c_value;
        }
        function getCookie(c_name) {
            var i, x, y, ARRcookies = document.cookie.split(";");
            for (i = 0; i < ARRcookies.length; i++) {
                x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
                y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
                x = x.replace(/^\s+|\s+$/g, "");
                if (x == c_name) {
                    return unescape(y);
                }
            }
        }
    </script>


Hey guys here i am calling
JavaScript
UpdateUserLogoutSession
in
JavaScript
window.onbeforeunload
event...
Now the problem is this works great on IE and Chrome..but it doesnt work on Firefox browser...
This function identify whether the page is REFRESHED or Closed........
So i want to use
JavaScript
UpdateUserResetSession 
on Refresh event and
JavaScript
UpdateUserLogoutSession
on close..!

Is there a way to do this in Firefox?
And Why it is not working?
One more thing....if i put
JavaScript
alert("hi");
after
C#
setCookie('session', sessionID, 1);
            var cookieSU = getCookie('session');
            if (cookieSU != null) {
                getSyncData('strSessionId=' + sessionID, 'UpdateUserLogoutSession');
            }
it just works great..but when i try without alert..it doesnt work?

Whats the problem?
Posted
Updated 4-Sep-12 3:48am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900