Implement refresh button

A

Andrus Moor

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 ?
 
K

kaeli

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
----------------------------------------
 
G

Grant Wagner

Andrus said:
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 <[email protected]>

* 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
 
E

Evertjan.

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>
 
E

Evertjan.

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


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 ????
 
G

Grant Wagner

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


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 <[email protected]>

* 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
 
I

istalcup

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top