I want upon unload detect the destinated url (how, this the problem)

I want upon unload detect the destinated url (how, this the problem)

  1. $(window).unload(function(){
  2.   alert("Goodbye1!");
  3.   if (window.location.indexOf("localhost/freelancerHelp/divsMoveShowPCH/")==-1) {
  4.     alert("Goodbye2!");
  5. }
  6. });

  7. // I want upon unload detect the destinated url (how, this the problem?) and appear a message only if not in my site the future url... how?