SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: page reload

  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    page reload

    i've got a small piece of javascript that i send out from my server (using php) only if this is the first visit in a session.

    the javascript gets the user's gmt offset time, puts that value in a cookie which lets my server read that value, via the cookie - *the next page visit*. so it's impossible to make use of the time offset that i get with javascript on the first page that the user goes to. the first page that's able to make use of the info is the second one the user goes to (or the same page but second hit - reload)

    the reason i want the user's time is for one particular page on my site. if this page isn't the first one they go to then there's not going to be a problem - i'll already have got their time and be ready to use it.

    BUT if they go to the page that needs the user's time first, there'll be a problem. and this is my question -

    is there a piece of javascript that'll set the required cookie (i've got that bit of code sorted) and automatically immediately reload the same page they're on, so the page that the user would be looking at would be infact a second page as it were - so i'd be able to make use of the cookie info even though this is the 'first' page they've come to

    possible?

  2. #2
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Surely you'd just make a function that you could call that writes the cookie and then performs a JScript refresh ... ? Should be easy I would've thought ...

    G

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by greg.harvey
    Should be easy I would've thought ...
    i'm sure it is but i've never really done any javascript - thought it'd be a good idea to ask people who knew about it, unlike me

  4. #4
    Drupaler bronze trophy greg.harvey's Avatar
    Join Date
    Jul 2002
    Location
    London, UK
    Posts
    3,258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure. I wasn't being rude ..... sorry. I'm not massively up on it myself but I can bodge together functions with my rudimentary knowledge ...... have quick look on Google for a refresh function and I know there are cookie writing functions out there. Then just bodge the two into the same function!

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if I read you correclty, you already have the js for writing the cookie. Find that code and immediately after the cookie is set, insert this line
    Code:
    top.location.reload();
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    yes i already have the 'set the cookie with time info' bit

    i thought it'd be something pretty simple but i just wanted to check.

    thanks

  7. #7
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    ahhh! it isn't working for some reason.
    is it something i've done wrong or maybe it's my browser? (mac os9 ie5.15)

    see for yourself here

    if it says "-0hr(s)" after your gmt offset: when you first go there, then it hasn't worked. click reload and then you'll get your gmt offset. if it says something other than -0hr(s) on your first visit then it has worked.

    what i'm trying to do is get the offset to display immediately (well pretty quickly - without a manual reload)

    any ideas? thanks

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhhh. My page just keeps refreshing...had to close it. Make sure you insert a flag of some-sort to prevent this.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  9. #9
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    oh no. i was wondering about that - why wouldn't it just keep reloading over and over? and it does!
    reload must not work on my browser at all then
    k
    thanks beetle, i'll have to go and think about this one

  10. #10
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What might work better than .reload() is this
    Code:
    if (!top.location.search)
    	top.location.href=top.location.href + "?reloaded";
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  11. #11
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,322
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    hey, great. thanks beetle - works very well

    see for yourself

  12. #12
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet! Glad it works
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •