Search code examples
htmlrefreshlimitmetarate

How can I limit the refresh rate on a website?


I know, that it's possible to define a time after which a html website is automatically refreshed. But is there a way to limit this rate, so that for example one can not hold the F5 key pressed in order to refresh the website "continuously"? Either in the html file itself or maybe on the server with some settings especially for that file?


Solution

  • If you be able to prevent to reload the page, you can prevent user for always to close your web site unless he/she close browser and this will be so bothering.

    Almost all you can do is to before reload page ask him are you sure? but you can't completely stop user to do that

    <script type="text/javascript">
        window.onbeforeunload = function() {
            return "are you sure you want to leave?";
        }
    </script>
    

    or you can disable F5 on keyDown event e occured

    if ((e.which || e.keyCode) == 82 || (e.which || e.keyCode) == 116) e.preventDefault(); };
    

    but If you want just limit the user from exceeding rate you can handle it by programming languages like PHP and ASP and save count of the visit in the user session and if exceed that number redirect him to some warning