1

I have a Login.html page from which I'm navigating to my Main.html

now when I;m doing a logout I want to navigate back to the login.html but I also want to ensure this page will be refreshed. I don't want to disable the page cache, I just want only in this specific scenario to navigate it after refresh.

I tried the following:
window.location.replace but it doesn't refresh the page.
window.location.href - also doesn't refresh the page.
window.location.reload() - Refresh only the current page.

@Christof13 suggestion regarding passing a parameter is the only way I can see but it loading the page twice and it's very ugly,

any other suggestions?

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • Add special headers to tell the browser to not cache the page http://stackoverflow.com/questions/49547/making-sure-a-web-page-is-not-cached-across-all-browsers – christof13 Jun 25 '14 at 11:38
  • @christof13 Thanks but I don't want to disable the page cache, I just want only in this specific scenario to navigate it after refresh. – Dor Cohen Jun 25 '14 at 11:44
  • Have you tried window.location.reload(true) ? – christof13 Jun 25 '14 at 11:46
  • @christof13 this will refresh the current page, it won't navigate me to the previous one – Dor Cohen Jun 25 '14 at 11:48
  • How about window.location.href = ? – Lave Loos Jun 25 '14 at 11:49
  • You pass a parameter to your previous page (QueryString) and if the parameter is present you call the reload in the previous page. The drawback is that the page will be loaded 2 times. – christof13 Jun 25 '14 at 11:50
  • @LaveLoos it doesn't refresh the page (see my edit) – Dor Cohen Jun 25 '14 at 12:03
  • @christof13 Yes I'm aware tot his solution but as you said the page will be loaded twice. – Dor Cohen Jun 25 '14 at 12:03
  • I don't think there's another solution unless you use dynamic pages (aspx, php,...) The cache directives are in the header and you won't be able to modify it with javascript. – christof13 Jun 25 '14 at 12:09

2 Answers2

0

How about setting a Timeout on the logout event? This way, the location reloads only once.

$("#myLogOutButtonOrLink").click(function() {
    setTimeout(function(){
        window.location.reload();
        }, 1000);
});
Lave Loos
  • 1,252
  • 1
  • 11
  • 15
0

My solution was using a global variable on the window scope as the following:

on main.html:

window.globals.RefreshRequired = true

on Login.html:

if (window.globals && window.globals.RefreshRequired) {
            window.location.reload();
        }

In this way the refresh will be done if I already visited main.html during the current browser instance.

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161