Implement refresh button

Discussion in 'Javascript' started by Andrus Moor, Jul 14, 2003.

  1. Andrus Moor

    Andrus Moor Guest

    I want to add a refresh button to my web page which works like browser
    refresh button:
    it must re-load current page from server.

    How to implement this in javascript ?
    Andrus Moor, Jul 14, 2003
    #1
    1. Advertising

  2. Andrus Moor

    kaeli Guest

    In article <>,
    shared the illuminating thought...
    > I want to add a refresh button to my web page which works like browser
    > refresh button:
    > it must re-load current page from server.
    >
    > How to implement this in javascript ?
    >
    >
    >


    <input type="button" name="btn1" onClick="document.location.reload
    (true)" value="Reload">


    --
    ----------------------------------------
    ~kaeli~
    There is no justification or rationalization
    for mutilation. Ban declawing as inhumane.
    http://www.ipwebdesign.net/wildAtHeart
    http://www.ipwebdesign.net/kaelisSpace
    ----------------------------------------
    kaeli, Jul 14, 2003
    #2
    1. Advertising

  3. Andrus Moor

    Grant Wagner Guest

    Andrus Moor wrote:

    > I want to add a refresh button to my web page which works like browser
    > refresh button:
    > it must re-load current page from server.
    >
    > How to implement this in javascript ?


    <a href="urlOfCurrentPage.html"
    onclick="window.location.reload(true);return false;">Refresh</a>

    or

    <a href="urlOfCurrentPage.html"
    onclick="window.location.href = 'urlOfCurrentPage.html?t=' + (new
    Date()).getTime();return false;">Refresh</a>

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    Grant Wagner, Jul 14, 2003
    #3
  4. Andrus Moor

    Evertjan. Guest

    Grant Wagner wrote on 14 jul 2003 in comp.lang.javascript:

    > <a href="urlOfCurrentPage.html"
    > onclick="window.location.reload(true);return false;">Refresh</a>
    >


    Why this return false ??

    The page is no longer active !!!

    why the true ?

    This is enough, I think:

    <a href="urlOfCurrentPage.html"
    onclick="location.reload();">
    Refresh
    </a>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 14, 2003
    #4
  5. Andrus Moor

    Evertjan. Guest

    Evertjan. wrote on 14 jul 2003 in comp.lang.javascript:

    > Grant Wagner wrote on 14 jul 2003 in comp.lang.javascript:
    >
    >> <a href="urlOfCurrentPage.html"
    >> onclick="window.location.reload(true);return false;">Refresh</a>
    >>

    >
    > Why this return false ??
    >
    > The page is no longer active !!!
    >
    > why the true ?
    >
    > This is enough, I think:
    >
    > <a href="urlOfCurrentPage.html"
    > onclick="location.reload();">
    > Refresh
    > </a>


    The second question I can answer myself:


    location.reload(boolean):
    false [Default]: Reloads the page from the browser cache.
    true: Reloads the page from the server.

    But I never saw any proof of that, does it work ????

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 14, 2003
    #5
  6. Andrus Moor

    Grant Wagner Guest

    "Evertjan." wrote:

    > Evertjan. wrote on 14 jul 2003 in comp.lang.javascript:
    >
    > > Grant Wagner wrote on 14 jul 2003 in comp.lang.javascript:
    > >
    > >> <a href="urlOfCurrentPage.html"
    > >> onclick="window.location.reload(true);return false;">Refresh</a>
    > >>

    > >
    > > Why this return false ??
    > >
    > > The page is no longer active !!!
    > >
    > > why the true ?
    > >
    > > This is enough, I think:
    > >
    > > <a href="urlOfCurrentPage.html"
    > > onclick="location.reload();">
    > > Refresh
    > > </a>

    >
    > The second question I can answer myself:
    >
    > location.reload(boolean):
    > false [Default]: Reloads the page from the browser cache.
    > true: Reloads the page from the server.
    >
    > But I never saw any proof of that, does it work ????


    I'm not sure if window.location.reload(true) guarantees a fresh copy
    from the server or not, which is why I also provided a unique URL
    solution as well.

    As for not returning false from the onclick. While you're right that in
    most cases, it is not necessary, at least one browser (IE 5.5) navigates
    (or begins to navigate to) the HREF immediately after returning from the
    onclick event. As a result, the navigation to the HREF tends to cancel
    any redirection you do in the onclick event. For example:

    <a href="#" onclick="document.forms[0].submit();">Submit</a>

    works in almost every browser except IE 5.5, which never submits the
    form.

    For this reason, I always return false to the onclick event (where
    applicable), even when in most cases, it will never be executed.

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    Grant Wagner, Jul 14, 2003
    #6
  7. Andrus Moor

    Guest

    hi,
    I used this code

    <input type="button" name="btn1" onClick="document.location.reload
    (true)" value="Reload">

    but it only works once! After I hit it once, all subsuqunet hits just
    keep showing old data. Does it anyone what is wrong?
    , Dec 23, 2004
    #7
    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. Jurjen de Groot

    Implement a Print button on ASP.NET webpage.

    Jurjen de Groot, Jun 25, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    25,822
    Joe Agster
    Jun 25, 2003
  2. brian lanning
    Replies:
    0
    Views:
    591
    brian lanning
    Jul 29, 2003
  3. Per Magnus L?vold
    Replies:
    1
    Views:
    5,116
    John C. Bollinger
    Oct 8, 2004
  4. Pkenty
    Replies:
    0
    Views:
    388
    Pkenty
    May 28, 2004
  5. Jawahar Rajan
    Replies:
    1
    Views:
    290
    Adrienne
    Oct 1, 2003
Loading...

Share This Page