Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.location.reload not working for Firefox and Chrome

I want to change the user status on click of a Button, so all I am doing is, detecting the current status and changing, if needed.

But in this case the changes the status in backend, but to show the status the page needs to be refreshed, as on refresh it checks the current status and shows. So I am using the "window.location.reload" property to show the latest status on page

All the things are working fine in IE. But in case of Firefox and Chrome, The status is not changing. I think "window.location.reload" is not working, because when I just comment this line and try clicking the button and manually refresh the page it shows the changes Status.

Can you please suggest what should I use to make this work in Firefox and Chrome?

When I googled, I found somewhere it works in Firefox and Chrome if you give it in "setTimeout()". I tried it, but even then its not working for me.

<script>

    $(document.body).on('click', '#activate', function () {
        var pkgVersion = $(this).attr('data-version');
        alert("@Url.Action("SetActivePackage", "Deployment")", { version: pkgVersion });
        $.get("@Url.Action("SetActivePackage", "Deployment")", { version: pkgVersion }).done(function () {

        });
         setTimeout(function () { window.location.reload(data); }, 0);
    });
</script>

Please suggest!

like image 791
UID Avatar asked Sep 23 '13 19:09

UID


People also ask

Is location reload deprecated?

Using location. reload() is the valid syntax. It is only the reload with forcedReload which is deprecated. In your case changing location.

What is the difference between location reload () and window location reload ()?

location. reload(true); reloads the page from the server instead of from the cache, window. location. reload(); would do the same thing as location.

Can I use window location reload?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

What is window location reload ()?

Window location. The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.


3 Answers

I have two other options to you:

history.go(0); 

And:

window.location.href = window.location.href; 

I'm not tested it on Firefox and Chrome yet, but it may help you faster. Tomorrow I'll do the tests and update the answer if this not work.

like image 148
Wellington Zanelli Avatar answered Oct 11 '22 23:10

Wellington Zanelli


I had this problem in AngularJS and in Firefox. (Reloading was fine in Chrome). By using setTimeout problem solved.

setTimeout(function(){
  window.location.reload();
});
like image 28
Morteza Ziyae Avatar answered Oct 11 '22 23:10

Morteza Ziyae


Have you tried this?:

window.location = window.location;

Apparently you can drop the "window.", but haven't tried it myself.

like image 25
Shylo Hana Avatar answered Oct 12 '22 01:10

Shylo Hana