SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sensing if cookies are supported?

    I'm thinking of using a pop-up on my site's homepage. I want the pop-up to appear only once (set a cookie), on the page's unload. I have the code for that so far.

    The only problem is: how can I sense if a user doesn't accept cookies or has cookies turned off? If this is the case, I don't want the pop-up to appear for this user, as it will appear each time the visitor accesses the homepage (the cookie will never set).

    I know the obvious way to do this is to set a test cookie and see if it reads the value you set, but for some reason this never works every time I try it.

    I'm using the code from: http://www.webmasterbase/static/popjs.php3 . (According to an article on SitePoint, it is free to use on your site.)

    If anyone knows any modifications I can do to this script, please post them here.

    I'd appreciate your help...

  2. #2
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have any ideas?

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With IE you can use the cookieEnabled property (boolean, returns true or false) of the navigator object. But I'm not sureabout Netscape etc.

  4. #4
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the tip. I have tried using this property, but then the problem was sensing if cookies are enabled in Netscape, which doesn't support this property.

    I think SitePoint.com uses a cookie-sensing script because I tried deleting all my cookies, disabling cookies, then visiting SitePoint.com, and browsing to another page (activating the onunload event), and the "newsletter subscribe" window didn't open. Then, I enabled cookies, and the window appeared only once (because cookies were enabled). I took a look at SitePoint's homepage code, and was kind of stumped, because it looks like it might use some PHP to set and receive the cookies.

    Any other ideas?

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have another go at setting a test cookie, then using document.cookies to see if it worked or not. Use the result to determine what you want to do. 'It will work' (chant that to yourself while you're doing it )

  6. #6
    SitePoint Addict
    Join Date
    May 2001
    Location
    USA
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks TechSited. I'll try the test cookie again. I'll let you know if it works out...('It will work', 'It will work')

  7. #7
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    UK
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, that's the spirit!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •