How can I refresh a page with jQuery?

后端 未结 28 2477
刺人心
刺人心 2020-11-22 07:00

How can I refresh a page with jQuery?

相关标签:
28条回答
  • 2020-11-22 07:38

    You can write it in two ways. 1st is the standard way of reloading the page also called as simple refresh

    location.reload(); //simple refresh
    

    And another is called the hard refresh. Here you pass the boolean expression and set it to true. This will reload the page destroying the older cache and displaying the contents from scratch.

    location.reload(true);//hard refresh
    
    0 讨论(0)
  • 2020-11-22 07:39

    The question should be,

    How to refresh a page with JavaScript

    window.location.href = window.location.href; //This is a possibility
    window.location.reload(); //Another possiblity
    history.go(0); //And another
    

    You're spoiled for choice.

    0 讨论(0)
  • 2020-11-22 07:39

    It is shortest in JavaScript.

    window.location = '';
    
    0 讨论(0)
  • 2020-11-22 07:40

    You don't need anything from jQuery, to reload a page using pure JavaScript, just use reload function on location property like this:

    window.location.reload();
    

    By default, this will reload the page using the browser cache (if exists)...

    If you'd like to do force reload the page, just pass a true value to reload method like below...

    window.location.reload(true);
    

    Also if you are already in window scope, you can get rid of window and do:

    location.reload();
    
    0 讨论(0)
提交回复
热议问题