SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast ratan's Avatar
    Join Date
    Feb 2006
    Location
    T.
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    stuff on first visit using javascript?

    Hi,

    I'm not tooo familiar with javascript.

    I was wondering if you guys could help me out or give me some pointers.

    I'm trying to load some content for the user only for the first visit.
    Im using a script that has built in functionality for regular visits and logged in users but no events to trigger anything on a first visit.

    The site is in Beta and I pretty much want to announce this on their first visit only. Strangely, I want to use some sort of lightbox effect to accomplish this.

    Any tips?

    Thanks in advance!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    first visit

    It sounds like a Cookie might be your best option.

  3. #3
    SitePoint Enthusiast ratan's Avatar
    Join Date
    Feb 2006
    Location
    T.
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, the trouble with that is, i don't know how to write cookies or process them. Do you know of any scripts that can do this?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    cookie scripts

    You can write and process cookies using javascript, PHP, etc., but AFAIK there are no "drop in" scripts. You will probably need to write your own custom code or have someone do it for you as what info the cookie will have and what you do with the info will be unique to your needs.
    It may be possible to find something close to what you need and then modify it. Sorry, I can't help there, but hopefully someone who can will post something more helpful.

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need to worry. PPK explains all on quirksmode.

    http://www.quirksmode.org/js/cookies.html
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek

  6. #6
    SitePoint Member
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I am in the same boat and there are a variety of documents that help. I found a popup script that loads only on the first visit: http://javascript.internet.com/cooki...opup-once.html

    I customized it to use a greybox instead of a standard popup. The only problem that I am having with this code is setting the cookie to be site-wide. here is the code I am looking at:

    Code:
    function SetCookie (name, value) { 
      var argv = SetCookie.arguments; 
      var argc = SetCookie.arguments.length; 
      var expires = (argc > 2) ? argv[2] : null; 
      var path = (argc > 3) ? argv[3] : null; 
      var domain = (argc > 4) ? argv[4] : null; 
      var secure = (argc > 5) ? argv[5] : false; 
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=/")) + 
    ((domain == null) ? "" : ("; domain=.")) + 
    ((secure == true) ? "; secure" : "");
    Does anyone have any idea of how i should be setting the domain and path to make my cookie site-wide?

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @bobman
    path=/
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek

  8. #8
    SitePoint Member
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks HeavyWeightGeek. I thought i had that in the code though. Is there some other way i need to write it?

    Code:
    ((path == null) ? "" : ("; path=/")) +

  9. #9
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @bobman
    nope
    Code:
    document.cookie =  'name =bobman; expires=Thur, 13 Dec 2007 23:17:11 UTC; path=/'
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek

  10. #10
    SitePoint Member
    Join Date
    May 2007
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @ HeavyWeightGeek,

    Thanks for your help. I implemented your code, but for some reason is still doesn't work. Do you have any idea what settings in the script would cause it to not go site-wide?

  11. #11
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @bobman
    You aren't moving between domains or sub domains are you?
    pm me an address and I'll have a look if you want.
    Mashups, DOM Scripting and all the things we call Web2.0 blogger
    http://www.heavyweightgeek.org/
    http://twitter.com/heavyweightgeek


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
  •