By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

Implement refresh button

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
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.