Solved

checking if cookie exists

Posted on 2002-03-29
5
173 Views
Last Modified: 2011-09-20
I set a cookie with Perl.  Now on each page, I'm going to include a piece of javascript that checks if the cookie exists.  I don't care what information the cookie holds because it doesn't matter.  I just want to know if the cookie exists.  If it doesn't exist, I'm going to redirect to an 'Error' page.  Any ideas?
0
Comment
Question by:GorGor1
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:GorGor1
Comment Utility
when I say 'each page', I mean that I'm going to include a piece of javascript on each HTML page.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
if (!document.cookie)
{
  //your re-direction code goes here
}




Cd&
0
 
LVL 1

Author Comment

by:GorGor1
Comment Utility
How does that code know which cookie I'm looking for?
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 50 total points
Comment Utility
Sorry brain fart:

var offset=-1;
if (document.cookie.length > 0) {
offset = document.cookie.indexOf("yourname=");}
if (offset == -1) { //re-direction code}


Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Glad I could help.  Thanks for the A. :^)

Cd&
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now