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?