How to reload a page using JavaScript

前端 未结 19 2504
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 00:46

How can I reload the page using JavaScript?

I need a method that works in all browsers.

相关标签:
19条回答
  • 2020-11-22 01:31

    This works for me:

    function refresh() {    
        setTimeout(function () {
            location.reload()
        }, 100);
    }
    

    http://jsfiddle.net/umerqureshi/znruyzop/

    0 讨论(0)
  • 2020-11-22 01:35

    To reload a page using JavaScript, use:

    window.location.reload();
    
    0 讨论(0)
  • 2020-11-22 01:37

    Shortest (more)

    history.go()
    
    0 讨论(0)
  • 2020-11-22 01:38

    Using a button or just put it inside an "a" (anchor) tag:

    <input type="button" value="RELOAD" onclick="location.reload();" />
    

    Try these for other needs:

    Location Objects has three methods --
    
    assign() Used to load a new document
    reload() Used to reloads the current document.
    replace() Used to replace the current document with a new one
    
    0 讨论(0)
  • 2020-11-22 01:40
    location.href = location.href;
    
    0 讨论(0)
  • 2020-11-22 01:42
    location.reload();
    

    See this MDN page for more information.

    If you are refreshing after an onclick then you'll need to return false directly after

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