I am using javascript to detect when a user leaves a page on my website. So I can detect when a user is leaving one of my pages but I dont know whether the user is going to another page in my website or outside my website.
I want to determine when the user is going to a page outside my website, so I can write to my server when the user left my site & record how long they were in my site (my own website analysis like googles).
So I know I can use javascripts onbeforeunload or onunload to detect when a user is leaving a page in mywebsite, but is there also a way to determine if they are going to an outside webpage(not any page in my site)?
Maybe there are some parameter passed with the onbeforeunload message/event?
function closeIt( param1 )
{
// where param1 maybe "http://...google.com";
if ( "MYSITE" in param1 ) { // they are going to a page inside my site }
}
window.onbeforeunload = cl开发者_StackOverflow中文版oseIt;
There is nothing you can do to know where they are going if they did something outside of your page to leave.
If they clicked a link on your page to leave your site, you can log stuff with the click event and try to record it, but you run into problems with browsers leaving before your call is made.
I think there shouldn't be a way to get the URL of a page outside your site. If there was it would violate the privacy of the user
精彩评论