简体   繁体   English

我想一键刷新我的页面 5 次

[英]i want to refresh my page 5 times on one click

How can i refresh my page 5 times on just one click here is my code我怎样才能一键刷新我的页面 5 次这里是我的代码

<!DOCTYPE html>
 <html>
  <head>
   <title>Page Title</title>
  </head>
<body>
   <button type="button" onClick="Refresh()">Close</button>

 <script>

function Refresh() {

for (var i=0; var i<5; var i++) {
    window.parent.location = window.parent.location.href;
}
}

You can add query string parameter refreshesLeft and on button click redirect to mypage?refreshesLeft=5 . 您可以添加查询字符串参数refreshesLeft并在按钮上单击重定向到mypage?refreshesLeft=5 Add onLoad handler to check if you have query string parameter set, and if yes, decrement it and redirect. 添加onLoad处理程序以检查是否设置了查询字符串参数,如果是,则递减它并重定向。

<button type="button" onClick="Refresh()">Close</button>

<script>

function Refresh(refreshesLeft) {
  refreshesLeft = refreshesLeft || 5;
  window.parent.location = window.parent.location.href + '?refreshesLeft='+refreshesLeft;
}

function onLoad() {
  let params = new URLSearchParams(document.location.search.substring(1)); 
  let rl = params.get("refreshesLeft")
  if (rl) Refresh( (rl | 0 ) -1)
}

document.addEventListener("DOMContentLoaded", onLoad)

</script>

nice @vittroe.不错@vittroe。 but this code has some problem.但是这段代码有一些问题。 it is printing refreshesLeft=5 many times (N numbers, which we set for refresh) in url, not 5,4,3,etc.它在 url 中多次打印 refreshesLeft=5(N 个数字,我们为刷新设置),而不是 5、4、3 等。

it creates url like this: https://myurl.com/hloo.php?refreshesLeft=5?refreshesLeft=5?refreshesLeft=5?refreshesLeft=5 and continue...它创建这样的网址: https://myurl.com/hloo.php?refreshesLeft=5?refreshesLeft=5?refreshesLeft=5?refreshesLeft=5并继续...

please solve this bug.请解决这个错误。 Thankyou谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM