Refresh page onclick of button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • daitasri
    New Member
    • Feb 2008
    • 18

    Refresh page onclick of button

    Hi,
    I m using javascript in HTML Page.And i want to refresh the page onclick of a button.I Tried with history.go(0) ;
    Its working fine but wil it cause any caching? I want to know some better way of refreshing ,because my html page is behaving very differently.

    Thanks
    daitasri
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    use a function like this:

    [CODE=javascript]function refresh_page() {
    window.location .href = window.location .href + '?' + (+ new Date);
    }[/CODE]
    the last section that we add avoids the caching through adding a timestamp to the request ...

    kind regards

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Does location.reload () not work?

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Originally posted by acoder
        Does location.reload () not work?
        that should work, but i don't remember how cross-browser compatible it is. I'd check it out first.

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          :) reload(true) should have the same effect - without the param it calls the page from the cache i think? ... and i think it should work with all browsers ...

          kind regards

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Yes, the forceGet parameter forces a reload from the server. If it's not specified, it could possibly be loaded from the cache.

            Comment

            • daitasri
              New Member
              • Feb 2008
              • 18

              #7
              Hi
              Thank you very much for your valuable help. It is working. Now i dont have any caching problem. :)

              Thanks
              diatasri
              Last edited by daitasri; Mar 14 '08, 04:19 AM. Reason: wrong reply

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Glad you got it working! Which solution did you use in the end?

                Comment

                • daitasri
                  New Member
                  • Feb 2008
                  • 18

                  #9
                  Originally posted by acoder
                  Glad you got it working! Which solution did you use in the end?
                  I used the following code :
                  [CODE=javascript]function refresh_page() {
                  window.location .href = window.location .href + '?' + (+ new Date);
                  }[/CODE]


                  Thanks
                  daitasri

                  Comment

                  Working...