简体   繁体   中英

Javascript to detect domain of previous page

I have a site logo that I want to animate (fade in) when a user first arrives into my domain. But, I do not want to animate this if the user arrives from another page in my domain.

I have the animation routine sorted (jquery) but I don't know how to detect when a user is landing on my site from elsewhere (link, or through typing in the URL).

I guess there might be an elegant javascript solution for this? Could anyone let me know what it might be...

Javascript has function document.referrer.split('/'); using this you should be able to find if they came from a page on your domain or not.

Hope this helps.

Example:

if(document.referrer.split('/')[2]!=location.hostname){
    //User came from other domain or from direct
}else{
    //User came from another page on your site
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM