Javascript Onfocus triggered on page load in firefox

below is my code…

$(window).load(function () {

            localStorage.setItem(breakbackToLogin + "userStatus", "loggedin");
            localStorage.setItem(breakbackToLogin + "userAthome", "yes");
            localStorage.setItem(breakbackToLogin + "session", jsessionId);

        });
        window.onfocus = function () {

            if (localStorage.getItem(breakbackToLogin + "userAthome") === "yes") {
                //  alert("I am if");
                if (localStorage.getItem(breakbackToLogin + "userStatus") !== "loggedin") {
                    // alert('inside if');                       
                    localStorage.setItem(breakbackToLogin + "userStatus", "loggedin");
                } else if (jsessionId !== localStorage.getItem(breakbackToLogin + "session")) {

                    window.location.reload();
                }

            }
            else {
                //   alert('I am else');

                if (localStorage.getItem(breakbackToLogin + "userStatus") !== "loggedin") {
                    // alert('inside else');
                    window.location.reload();
                }
            }
        };

After logging in, in the home page, in localstorage “loggedin” value will be set. ie. load function is getting executed. This thing is working in chrome, safari and explorer. But in firefox alone onfocus event is triggered while the page is loading. Because of that focus thing, my home page is continuously reloading until the focus is removed from that page. How to solve this issue ?


Source: jquery

Leave a Reply