8

After a user has logged in via a fancybox (javascript) popup I wish to reload the parent page so they can access the logged in features.

Currently I am doing this with:

<a href="javascript:window.top.location.reload(true)" class="continue">Continue</a>

This works great, but the only issue is that it completely reloads the entire page: redownloads all the css & javascipt, etc.

All I want to do is reload the page normally, not a full refresh. How can I achieve this?

(I do not know the exact URL because the login can be done from any page via the fancybox, so I can't hardcode the URL.)

Alasdair
  • 13,348
  • 18
  • 82
  • 138

2 Answers2

16

Another way of reloading the page i have seen in the facebook graph api is the following:

window.location = window.location

or in your case:

window.top.location = window.top.location

This solution reloads the page without trying to resend a POST request. Might be useful. for more information look at the following SO question.

Community
  • 1
  • 1
decden
  • 679
  • 4
  • 19
  • Ah this is very fast. Just reloads the HTML only. Exactly what I want, thank you. – Alasdair Apr 09 '13 at 08:59
  • 1
    Unfortunately this seems not to work when there is a hashtag in the URL (at least on my Firefox 26). – tzot Jan 12 '14 at 16:55
  • Then you could use something like the following: `window.top.location = (window.top.location.hostname + window.top.location.pathname)`. Should work in any browser (source http://www.w3schools.com/jsref/obj_location.asp) – decden Jan 14 '14 at 08:39
  • mate, thanks. so damn simple, yet effective solution! – Rossitten Nov 02 '15 at 06:44
1

Use:

location.replace(location.href.split('#')[0]);

The split on hash is required, otherwise an url with a hash will not be refreshed.

If you want to keep the previous load in browser history, use assign instead of replace.

href is not currently supported by Opera, according to MDN.

Frédéric
  • 9,364
  • 3
  • 62
  • 112