I would like to fire js code in angularjs controller.
I have this:
$scope.$on('$destroy', function () {
alert('page1');
});
This is working fine when I'm navigating away from the page which is using that controller but its not working when I'm closing tab/browser.
Do I need to use some other code to fire js code when tab/browser is closing?
Thanks in advance, Laziale
From the angular docs:
This just handles the situation where the scope itself is being destroyed, that does not seem to occur when the tab/browser is closed though.
You will have to use lower level methods onunload and onbeforeunload events to handle this situation, here is another post you may find useful:
javascript detect browser close tab/close browser