How To Create A Cookie That Checks To See If A User Has Been To My Homepage
Solution 1:
This site has very good tutorial on cookie as well as example for creating and reading them http://www.quirksmode.org/js/cookies.html
So on homepage you can create cookie using function createCookie(name,value,days) and read it on other pages using function readCookie(name)
So you can check value and redirect using window.location = "http://www.any_url.com/" in JavaScript
Solution 2:
You would want to do this on the server-side, since you wouldn't want the user to download the whole page, and then get redirected to download the home page too.
How to do it server-side depends on what language you are using.
On the other hand, you might not want to do this at all. What happens if the user doesn't accept cookies? Will he not be able to visit any page other than the home page on your site?
Solution 3:
Before telling you how to do this, I want to say don't do this. As a visitor, when I click a link to a specific page, I expect to end up on that page. If I'm redirected to your homepage, I'll be frustrated and most likely leave your site – it's too much work to have to find the content I'm looking for after being redirected to a homepage I'm not interested in.
This happens to me all the time when I click links to news articles on my phone. Instead of the article I'm interested in, I get redirected to the site's mobile version homepage. I promptly lose interest and close the tab.
So do your visitors a favor and don't break their expectations. Make it easy for them to get to your homepage if they want to, but don't force it.
So that said, let's call this an academic exercise. Using jquery-cookie:
Homepage:$.cookie('seenhp', true, { expires: 365 });
Other pages:if (!$.cookie('seenhp')) location.assign('/index.html');
Post a Comment for "How To Create A Cookie That Checks To See If A User Has Been To My Homepage"