0

I need to logout an user if he/she tries to submit any valid URL from the address bar?

I tried jQuery on items below but it is not working.

  1. window.location.href
  2. window.unload

unload code

    (window).unload(
       function(event) {
       //code to handle
     });

location href code

     (function() //create a scope so 'location' is not global
        { var location = window.location.href;
          setInterval(function()
          {
            if(location != window.location.href)
            {
              location = window.location.href;
              window.location.changed(location);
            }
          }, 1000);
        }
      )();
      window.location.changed = function(e)
      {        console.log(e);//outputs http://newhref.com
        //this is fired when the window changes location
      }
  • 1
    Javascript can't take action when the user tries to navigate away from the page, this would be a security violation. This is how adware used to prevent people from closing the page. Use a timeout on sessions. – Barmar Jan 01 '16 at 10:54
  • How did you "try jQuery on below items" ? What did you do with them? Show us. – Rudie Jan 01 '16 at 11:49
  • @Rudie added both code in description – Fahim Babar Patel Jan 01 '16 at 17:23
  • [onbeforeunload](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload) – LJᛃ Jan 01 '16 at 21:49
  • @LJᛃ In between other alternative. Will update once I check onbeforeunload. – Fahim Babar Patel Jan 04 '16 at 08:55
  • @LJᛃ I checked onbeforeunload. This event get executed even on click of URL. There is no way to capture button click of navigation box. It is not helpful in this scenario. – Fahim Babar Patel Jan 04 '16 at 14:00

0 Answers0