469,271 Members | 1,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Implement refresh button

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 ?
Jul 20 '05 #1
6 14145
In article <3f********@news.estpak.ee>, no**************@online.ee
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
----------------------------------------
Jul 20 '05 #2
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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #3
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)
Jul 20 '05 #4
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)
Jul 20 '05 #5
"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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #6
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?

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Mark | last post: by
4 posts views Thread by Andrew Alger | last post: by
6 posts views Thread by laura | last post: by
1 post views Thread by ppatel | last post: by
9 posts views Thread by PK9 | last post: by
3 posts views Thread by Sameer | last post: by
4 posts views Thread by puja patel | last post: by
3 posts views Thread by =?Utf-8?B?cm9kY2hhcg==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.