1

As you know the code

window.onbeforeunload = function(){
 return 'my message';
};

runs the alert before user leaves a page OR reloads current page OR jumps to another page of the same website. Is there some solution only for the case when the user leaves the website (domain) by closing the tab of browser?

user3892905
  • 376
  • 1
  • 4
  • 14
  • you could check this out: [link](http://www.w3schools.com/jsref/event_onunload.asp) – Doml The-Bread Mar 11 '15 at 09:53
  • It's the same I have (including "the user navigates away from the page" but doesn't leave the website), but I need ONLY the user leaves the website (domain) – user3892905 Mar 11 '15 at 09:59
  • Do you mean a solution when the user whether click a link to another page (not in the same domain) or enters another URL in the url bar? – briosheje Mar 11 '15 at 10:00
  • I think you want to check this: http://stackoverflow.com/questions/2063963/a-way-to-observe-url-in-urlbar-of-firefox-and-get-an-event-every-time-it-change and this: http://stackoverflow.com/questions/2060779/how-can-i-check-if-url-of-current-browser-tab-is-changed – briosheje Mar 11 '15 at 10:02
  • it's not the same, you got `onbeforeunload` - _onunload occurs when the user navigates away from the page_ – Doml The-Bread Mar 11 '15 at 10:03
  • Oh sorry, but with `window.onunload = function(){return 'my message';};` nothing happens – user3892905 Mar 11 '15 at 10:06

0 Answers0