1

I write a jQuery event

$(window).unload(function() {
            console.log('cool');
        });

When I close the tab then unload event will be trigger.

But, When I change my Url http:/localhost/#home to http:/localhost/#profile.

Unload event doesn't work. Why?

Aaron D
  • 6,424
  • 3
  • 38
  • 45
  • 1
    The page doesn't unload when the url hash fragment changes. [This question](http://stackoverflow.com/questions/2161906/handle-url-anchor-change-event-in-js) may help? – James Thorpe Aug 10 '15 at 12:00

1 Answers1

2

Because the page isn't unload. The hash is used to anchor elements or to design a single page layout for all application. You must to change your event to hashchange

  $(window).on('hashchange', function() {
    // stuff
  });
Marcos Pérez Gude
  • 20,206
  • 4
  • 34
  • 65