Tuesday, December 8, 2009

Reloading page using javascript

Two ways to reload a page using javascript:
window.location.reload();
and
window.location.href = window.opener.href;

both will send GET parameters. The former will also send POST parameters (usually you get a pop-up box asking if you would like to re-send post parameters or not do the page reload at all (which can be annoying)).

To set what GET parameters should be used use among other things the split() function on the string window.location.href:
splitArray = window.location.href.split("?");
window.location.href = splitArray[0];

and get parameters by splitting the second part of the splitArray on the &.

Adding opener after window will address the reload to the window which opened the current page:
window.opener.location.href

Solution sources: http://bytes.com/topic/javascript/answers/648770-problems-reloading-same-page-new-parameters

No comments:

Post a Comment