How to capture browser refresh event using javascript

I need to navigate to a specific page / start page of my application when the user clicks the refresh button on any other page of my application. I need a javascript function for this. Someone suggest the best way. thank.

The code I have tried is

 window.onbeforeunload = function (evt) {
              if (evt) {
                  evt.stopPropagation();   
                  console.log("refreshed in appBootstrap");
                  console.log("current url is "+location.href)
                  window.location.href= "/scm/mgmt/case";
                  console.log("relocated")




                    }
               }

      

This does not redirect me to the intended page, but stays on the same page on refresh. I need to go to the specified url every time on the update page.

+3


source to share


1 answer


You can try the counter thing. if count is 2 than redirect to the required page.



or you can try it document.referrer

but some browsers may not support it.

+2


source







All Articles