How can I refresh a page with jQuery?

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

How can I refresh a page with jQuery?

28条回答
  •  失恋的感觉
    2020-11-22 07:19

    There are multiple unlimited ways to refresh a page with JavaScript:

    1. location.reload()
    2. history.go(0)
    3. location.href = location.href
    4. location.href = location.pathname
    5. location.replace(location.pathname)
    6. location.reload(false)

      If we needed to pull the document from the web-server again (such as where the document contents change dynamically) we would pass the argument as true.

    You can continue the list being creative:

    • window.location = window.location
    • window.self.window.self.window.window.location = window.location
    • ...and other 534 ways

    var methods = [
      "location.reload()",
      "history.go(0)",
      "location.href = location.href",
      "location.href = location.pathname",
      "location.replace(location.pathname)",
      "location.reload(false)"
    ];
    
    var $body = $("body");
    for (var i = 0; i < methods.length; ++i) {
      (function(cMethod) {
        $body.append($("
    button {
      background: #2ecc71;
      border: 0;
      color: white;
      font-weight: bold;
      font-family: "Monaco", monospace;
      padding: 10px;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.5s ease;
      margin: 2px;
    }
    button:hover {
      background: #27ae60;
    }

提交回复
热议问题