Change page refresh timer

Viewed 30

I have a specific requirement where my page refreshes after 2 seconds. I have used this code to achieve this functionality -

<?php
    $page = $_SERVER['PHP_SELF'];
    $sec = "2";
?>
<html>
    <head>
        <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    </head>
</html>

Now I require a button which changes the refresh time from 2 to lets say 10 seconds for a different functionality.

It would be of great help if someone suggests how I should achieve this. Thankyou

1 Answers

add button with js code: in HTML

<button onclick="fnc()">Button</button>

add tag ID in meta

<meta id="ref" http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    

add js script into your page

<script>
  function fnc() {
    const d = document.getElementById('ref')
    d.content = 10;
  }

</script>

UPD: result page:

<?php
    $page = $_SERVER['PHP_SELF'];
    $sec = "2";
?>
<html>
    <head>
        <meta id="ref" http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    <script>
        function fnc() {
        const d = document.getElementById('ref')
        d.content = 10;
        }    
    </script>
    </head>
    <body>
        <button onclick="fnc()">Button</button>
    </body>
</html>
Related