Home > Enterprise >  Update page 10 second
Update page 10 second

Time:10-05


I don't know how to say it right, sorry in advance.
I want to make a page of the site js that the page can be updated every 10 seconds, does anyone have an example?

**that the user can refresh the page every 10 seconds**
I want my user on my site to be able to refresh the page once every 10 seconds

CodePudding user response:

You can make button that will show after 10 seconds so user can but also don't have to update.

setTimeout(function(){
   let button = document.querySelector('button');
   button.style.display = "block";
   button.onclick = () => window.location.reload();
}, 10000);

window.onkeydown = (e) => {
  if(e.key === 'F5'){
    e.preventDefault()
  }
}
button {
display:none;
}
<button>Click me</button>

CodePudding user response:

EDIT: It is impossible to prevent the user from reloading the page, however it is possible to ask if they really want to leave, using this code below, if it after 10 seconds it will not ask if they want to leave, however if it has been less than 10 seconds, it will ask if they want to leave.

var r = 0;

window.onbeforeunload = function() {
if(r == 1) {
        return "Are you sure you want to leave?";
}
    }

setTimeout(function(){
    r = 0;
    }, 10000);
  • Related