By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,639 Members | 2,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,639 IT Pros & Developers. It's quick & easy.

Check for cookie on page load and redirect to another page if found

P: 2
I am trying to add a code to my contact page that checks for a cookie named NewCookie, and if this cookie is found it will redirect the user to another page called alreadysubmitted. I have tried everything I can,.
Dec 1 '13 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
so, what was it that you have tried?
Dec 1 '13 #2

P: 2
I have tried the onload command and tried to break down ones like this but I am very new to javascript and I believe with all the site and things I have tried I have made myself very confused.



Expand|Select|Wrap|Line Numbers
  1. function getCookie(NewCookie)
  2. { if (document.cookie.length > 0)
  3. { begin = document.cookie.indexOf(NewCookie+"=");
  4. if (begin != -1)
  5. { begin += NewCookie.length+1;
  6. end = document.cookie.indexOf(";", begin);
  7. if (end == -1) end = document.cookie.length;
  8. return unescape(document.cookie.substring(begin, end)); }
  9. }
  10. return null;
  11. }
  12.  
  13.  
  14.  
  15. function setCookie(NewCookie, Website cookie value, expiredays)
  16. { var ExpireDate = new Date ();
  17. ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
  18. document.cookie = NewCookie + "=" + escape(value) +
  19. ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
  20. }
  21.  
  22.  
  23.  
  24. function delCookie (NewCookie)
  25. { if (getCookie(NewCookie)) {
  26. document.cookie = NewCookie + "=" +
  27. "; expires=Thu, 30 Dec 2013 00:00:01 GMT";
  28. }
  29.  
  30. }
  31.  
Dec 1 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.