开发者

determine when user leaving the site

I want to determine when user is leaving the site using javascript. By site I means domain here.

The body unload occur before leaving any page. So it won't do the job. But is there any way to capture where the user is headed? So when the address is on another domain something is alerted by this event.

Another way, attach an onclick or onsubmit to any inner form and inner link. On this events we set a variable so on unload understand that we are going to an in开发者_如何学编程ner page. Maybe you suggest a script that do that automatically but without any javascript framework.

Dears, I don't want to use this as a "please, stay on my site". I want to ask those user that go to order page but anyhow can't submit and finalize the order, and leaving our site to contact us on the phone. So please don't judge it.


This question is very similar, and like others I would encourage you not to do this for privacy reasons. Knowing when users leave your site is going to be near impossible; if instead you want to track when people use links on your site to leave your site, you can impliment click tracking via various means: Piwik is one, you can also use some PHP libraries if you have the option.

You cannot however check what URL a user has entered into the search bar; that would be a huge privacy invasion.


If a user types in the URL into his browser, you have no way of knowing what was requested. If he clicks an external link, you again have no way of detecting AFAIK.

However, you can create a redirect page on your server and rewrite all links on the page to point to that page, for instance www.ExternalSite.com is changed to http://www.example.com/redirect.php?u=www.ExternalSite.com. This is how Facebook used to do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜