Search code examples
javascriptonbeforeunload

How can I detect when a visitor leaves my page/site on our corporate intranet and where they're going?


On our internal intranet, we have several embedded help files linked to from within our internal applications. I'm trying to determine whether or not the user is solely using our internal help files specific to the application or if they're visiting other resources such as our internal wiki, forums, newsletters, etc.. or possibly external sources.

I tried using onbeforeunload to return document.location.href, but it doesn't work as I need it to. For example, if the user is at internalhelp.company.com/page1.html and then leaves the page to go to internalwiki.company.com/wikipage1.php, the onbeforeunload returns internalhelp.company.com. I need it to return internalwiki.company.com.

Any help would be greatly appreciated.

Thanks.


Solution

  • For privacy reasons, this is totally impossible.

    If you're only interested in hyperlinks, you could add a click handler to all <a> tags which sends an AJAX request telling you that the link was clicked (or use a server-side interstitial page)