1

I am trying to make a webpage refresh at a certain time, for this I will be doing some calculations using java script to define when the webpage must be refreshed.

I am using this code but the content attribute for the meta tag is not changing.

<script language="javascript"  type="text/javascript">


function myFunction() {

    document.getElementsByTagName('META')[0].getAttribute("content")="5";

}

    myFunction();
</script>

2 Answers2

0

You can do it like this in vanilla JS (the example changes the meta tag with the name "keywords")

document.getElementsByName("keywords")[0].setAttribute("content", "dynamic meta description");

But to solve your problem i would not use the header tag, but a javascript timer, that reloads the page

location.reload(); 
BobbyTables
  • 4,481
  • 1
  • 31
  • 39
0
<!DOCTYPE html>
<html>
    <head>
        <META HTTP-EQUIV="Content-Language" charset="UTF-8">
        <meta http-equiv="refresh" content="30">
        <script type="text/javascript" src="http://localhost:8080/files/jquery.min.js"></script>
        <link rel="stylesheet" type="text/css" href="http://localhost:8080/files/bootstrap.css">
    </head>
    <body>
        <div>
            click <button type="button" onclick="refreshTime()">here</button> to change page refresh time.
        </div>

        <script>
            var refreshTime = function(){
                var time = Number(prompt('set refresh time',30));
                $("meta[http-equiv='refresh']").attr('content',time);
            }
        </script>
    </body>
</html>
Ritesh Dhuri
  • 215
  • 2
  • 7