View Full Version : Refreshing a jsp using javascript!!

11-03-2006, 02:43 PM
Hi all,
I wanted to Reload the whole page again after doing a particular action on the page. Is there a refresh or reload functionality using javascript??
Other than onLoad() in body, but this should be called in a middle of our html code...

Thanks and Regards,

11-04-2006, 06:53 AM
Usually it is possible and always is better to design your page and plan out whatever it needs to do without having to refresh it after it is loaded. This can have predictably bad consequences for forms and unexpectedly bad consequences in other areas of sever-side code.

That being said, javascript does provide us with several methods to reload the page. I have put several of them together in one function that tests each before using it against the browser's ability to support it. I've ordered them from the most efficient and modern to the least efficient and archaic:

function doit(){
if (window.location.reload)
window.location.reload( true );
else if (window.location.replace)

This is by no means meant to be exhaustive but, will probably handle the vast majority of browsers out there without resorting to any sort of browser testing.

You probably also need a hook to execute the doit() function on but, I'm unclear as to what sort of condition(s) and/or circumstance(s) you would want to trigger this. If things like onresize, onload, etc. won't do (and these type of events have special considerations) then either a poll (last resort) or a hook into an existing bit of code (generally best) would suit. The way a poll works is to periodically test if a certain condition or set of conditions is true and then execute something if they are but, it can take up a lot of resources in many cases.