views:

31

answers:

3

A client is looking to play a brief splash javascript animation whenever a user accesses their site for either the first time or after visiting another domain. So as long as they are not navigating within the site.

Essentially, I'm looking to set a cookie and delete it if they leave the domain or capture what's going on in the URL bar, and I realize it might be impossible for security/privacy reasons, but wanted to check if any genii around here might have an idea for a hack. This is my nearest failed attempt at a full solution:

function del_cookie() {
    var baseUrl= 'mydomain.com';

    var currUrl = document.location.href;                                                                            

    var splitUrl = currUrl.split('/');                                                                               

    var currBaseUrl = splitUrl[2];                                                                                   

    if(currBaseUrl != baseUrl) {                                                                                     
    document.cookie = "animation=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";                                     
    }               
} 

<body onunload="del_cookie()">

Naturally, the currUrl has not updated to the new URL at this point, so this won't work.

It seems the best solution I might have is to only control the animation on clicks and changes inside of the DOM and leaving the address bar out of things. But does anyone else have an idea?

A: 

Just to add to this question (also working on this same issue).

Basically when you're on mydomain.com and browse to mydomain.com/page, the del_cookie knows that it's still within mydomain.com, so no cookie got deleted. but when you click on Yahoo bookmark or type in yahoo.com, currUrl still thinks that you are still on mydomain.com. is there a way to retrieve the upcoming/to-be-loaded URL?

Here's the flow that the user wanted: 1:open one new single browser window 2: go to mydomain.com 3: see loading screen. 4: if you click on a link on mydomain.com, it WON'T reload the animations & loading screen.
5: Then lets say I go to www.digg.com or www.gizmodo.com 6: leave gizmodo.com 7: decide to go back to mydomain.com 8: we SHOULD see the splash page again.

the "splash page" is a div that gets shown when javascript detects no cookie is set. it loads the splash page animation and sets a session cookie.

Koes Bong
Not from the webpage, no. A browser extension will have access to this data, but your users would have to install that extension first.
Piskvor
That's what I thought :-/
Koes Bong
A: 

If I understand you, you want to a splash screen to show up at any entry point into the site, not just the home page (for example.)

One technique might be to check the HTTP_REFERER header (sic). If it's empty or is a different domain than the current site's domain, it's highly likely it's the first visit [for this session.]

-Oisin

x0n
A: 

Looks like in the end, this was impossible. Answered here for posterity's sake.

Joshua Cody