DelphiFAQ Home Search:

Reload a web page with a javascript function

 

comments23 comments. Current rating: 5 stars (4 votes). Leave comments and/ or rate it.

Question:

I need to force a page reload from a javascript function but document.reload() seems not to work. How do I do it?

Answer:

The document object is not used to reload a window, that is the reason for your problem. Below are three examples, in these cases in the onclick event.

This code will reload the current window. If it is shown in a frame, then only this frame will be reloaded. If you need to reload another frame, then you may want to address it as shown in the last 2 examples.

<input type="button" value="Reload Page" onClick="window.location.reload()">

<input type="button" value="Reload Page" onClick="history.go(0)">

<input type="button" value="Reload Page" onClick="window.location.href=window.location.href">

<input type="button" value="Reload 1st Frame" onClick="window.parent.frames[0].location.reload();">

<input type="button" value="Reload 2nd Frame" onClick="window.parent.frames[1].location.reload();">

Content-type: text/html

Comments:

You are on page 1 of 2, other pages: [1] 2
2008-05-09, 11:13:06
anonymous from Brazil  
very good examples, thank you!
2008-06-23, 04:39:43   (updated: 2008-06-23, 04:40:16)
anonymous from Lebanon  
very good tip! Thank you keep the good work`
2008-06-24, 02:55:12
anonymous from South Africa  
Syntax:
document.location.reload([bReloadSource]);

Parameters
bReloadSource Optional. Boolean that specifies one of the following values:
- false : Default, reloads the page from the browser cache.
- true : Reloads the page from the server.

2009-11-19, 03:05:21
anonymous from Spain  
Hi, well done. Your tip has been very useful!
2009-11-24, 10:21:35
anonymous from United States  
rating
window.location.href can't working in IE8
2010-04-05, 14:17:56
anonymous from United States  
rating
thanks! i've been trying to figure this out all day for a button to reload the weather on my home page, but nothing else I tried worked!
2010-05-11, 09:49:22
anonymous from Vietnam  



Keywords:
2010-05-11, 09:51:16
anonymous from Vietnam  



Keywords:
2011-10-27, 23:56:30
anonymous from Malaysia  
hurm
2011-12-27, 08:16:15
anonymous from Cranston, United States  
rating
2012-02-09, 03:48:17
anonymous from Ghana  
2012-06-05, 21:34:36
anonymous from China  
<strong> http://www.coachout..strong> <a href=' http://www.coachout..g>Coach Outlet Online</strong></a><br />
<strong> http://www.coachfac..strong> <a href=' http://www.coachfac..g>Coach Factory</strong></a><br />
<strong> http://www.myloveco..strong> <a href=' http://www.myloveco..g>Coach Outlet Online</strong></a><br />
<strong> http://www.buyincoa..strong> <a href=' http://www.buyincoa..g>Coach Outlet</strong></a><br />
<strong> http://www.cheapcoa..strong> <a href=' http://www.cheapcoa..g>Cheap Coach Handbags</strong></a><br />
<strong> http://www.coachfac..strong> <a href=' http://www.coachfac..g>Coach Factory Outlet</strong></a><br />
<strong> http://www.buycoach..strong> <a href=' http://www.buycoach..g>Coach Outlet Online</strong></a><br />
<strong>www.coachoutletonfactory.net</strong> <a href=' http://www.coachout..g>Coach Factory Outlet</strong></a><br />
<strong>www.coachoutletonline4you.us</strong> <a href=' http://www.coachout..g>Coach Outlet Online</strong></a><br />
<strong>coachfactoryoutletq.net</strong> <a href=' http://www.coachfac..g>Coach Factory</strong></a><br />
<strong>gotocoachoutlets.net</strong> <a href=' http://www.gotocoac..g>Coach Outlet Online</strong></a><br />
2012-06-17, 20:28:54
Louis Vuitton from United States  
the Thunder couldn't come back from a double-digit deficit after
<a href=' http://www.louisvui..'>Louis Vuitton Purses</a> spotting Miami a 17-point

advantage during <h1><a href=' http://www.louisvui..'>Louis Vuitton Purses</a></h1> their

worst first half of the season.'That was the game. We can't start off down 18-2,' Durant said. 'We can't go

down that much, <a href=' http://www.louisvui..tle='Louis Vuitton Purses'>Louis Vuitton

Purses</a> especially at home. We've got to correct itIt was the first home loss in 10 postseason games for

the Thunder, <h1><a href=' http://www.lvshopos..tle='Louis Vuitton Bags'>Louis Vuitton

Bags</a></h1> who had overcome a 13-point deficit in Game 1.James had what was his career high, 30 points,

in the opener, but afterward said Wade needed to be Wade -- All-Star,

[url= http://www.chanelou..et/]Chanel Bags[/url] Olympic gold medalist and finals MVP.In Game 1,

Wade was 7-of-19. He wasn't sharp in the last round and continues to hear reports that something is

physically wrong with him. He was all but asked Wednesday if his explosiveness was a thing of the past,
You are on page 1 of 2, other pages: [1] 2

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: