page onload/refresh

Discussion in 'ASP General' started by Mike, Apr 8, 2008.

  1. Mike

    Mike Guest

    Is there a way to determine if a page was refreshed? I have a function that
    is called when the page loads, but when the user refreshes the page it calls
    the function again. Is there a way to call the function only when the page
    initially loads? I don't want it to load when the user clicks the refresh
    button.
    Mike, Apr 8, 2008
    #1
    1. Advertising

  2. Mike

    Evertjan. Guest

    Mike wrote on 08 apr 2008 in microsoft.public.inetserver.asp.general:

    > Is there a way to determine if a page was refreshed? I have a function
    > that is called when the page loads, but when the user refreshes the
    > page it calls the function again. Is there a way to call the function
    > only when the page initially loads? I don't want it to load when the
    > user clicks the refresh button.


    If you mean a serverside function, as you should in this NG:

    Yes, look for the referrer.
    This is not serverside foolproof, as you use a browser header.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Apr 8, 2008
    #2
    1. Advertising

  3. "Mike" <> wrote in message
    news:%...
    > Is there a way to determine if a page was refreshed? I have a function

    that
    > is called when the page loads, but when the user refreshes the page it

    calls
    > the function again. Is there a way to call the function only when the page
    > initially loads? I don't want it to load when the user clicks the refresh
    > button.
    >



    If this is for a standard page GET then there is no absolutely reliable way
    to determine whether the request is the result of refresh. The presence of
    a Pragma: no-cache header is a clue but IE will often add that header to a
    request for a page the first time its requested in a session also.

    Setting a session cookie might help (make sure you set the cookie path to
    the full path of your page). If the cookie is not present then it will be
    the first time the request is being made. If it is then the request has
    been made in that session before.

    You might be able to combine the two to get something fairly reliable. If
    the session cookie is present but pragma: no-cache isn't then the user has
    navigated back to the page normaly without a refresh.

    But then you need to consider other browsers, FF for example behaves in
    somewhat more predictable way, and its fairly safe to test for
    pragma:no-cache to detect a refresh.

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Apr 8, 2008
    #3
  4. "Evertjan." <> wrote in message
    news:Xns9A7AE0EA44D39eejj99@194.109.133.242...
    > Mike wrote on 08 apr 2008 in microsoft.public.inetserver.asp.general:
    >
    > > Is there a way to determine if a page was refreshed? I have a function
    > > that is called when the page loads, but when the user refreshes the
    > > page it calls the function again. Is there a way to call the function
    > > only when the page initially loads? I don't want it to load when the
    > > user clicks the refresh button.

    >
    > If you mean a serverside function, as you should in this NG:
    >
    > Yes, look for the referrer.




    That won't help. A refresh pretty much repeats the original request,
    therefore the referrer in a refresh will be the same same as in the original
    navigation.

    --
    Anthony Jones - MVP ASP/ASP.NET
    Anthony Jones, Apr 8, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabio R.
    Replies:
    0
    Views:
    792
    Fabio R.
    Mar 25, 2005
  2. Pkenty
    Replies:
    0
    Views:
    388
    Pkenty
    May 28, 2004
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    545
    Martin Honnen
    Nov 4, 2004
  4. Replies:
    5
    Views:
    257
    Thomas 'PointedEars' Lahn
    May 15, 2005
  5. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    202
    marco
    Jun 24, 2006
Loading...

Share This Page