通过javascript动态更改元标记内容

Amr*_*esh 5 html javascript meta-tags

我想使用 javascript 动态更改元标记内容,即刷新率和 url。使用按钮启用 javascript 功能。尝试了 3 种替代方法,但没有奏效。请帮忙。

谢谢,阿姆雷什

<!DOCTYPE html>
<html>
<head>
<meta HTTP-EQUIV="refresh" name="description" id="mymetatag"
      content="5;URL=http://localhost:6985/ChartJSDemo/Is_Mainpage.html">
<meta charset="ISO-8859-1">

<title>Processing Details</title>
<link rel="stylesheet" type="text/css" href="css/MF_job_failTable.css">
</head>

<body>

<button onclick="myFunction()">Click me</button>

<script>
function myFunction() {
    <!--document.querySelector('meta[name="description"]').setAttribute("content","5;URL=http://google.co.in");-->
    <!--document.getElementById("mymetatag").setAttribute("content", "5;URL=http://google.co.in");-->

  var m = document.createElement('meta'); 
  m.name = 'description'; 
  m.id = 'mymetatag';
  m.content = '5;URL=http://google.co.in'; 
  m.HTTP-EQUIV= 'refresh';
  document.head.appendChild(m);
}
</script>
Run Code Online (Sandbox Code Playgroud)

Chr*_*isR 3

这对我有用。问题可能是您尝试了第一个代码,但该代码不起作用,并且您使用 HTML 注释<!-- [...] -->而不是 Javascript 注释对代码进行了注释:// [...]/** [...] */

<!DOCTYPE html>
<html>

<head>
  <meta HTTP-EQUIV="refresh" name="description" id="mymetatag" content="5;URL=http://localhost:6985/ChartJSDemo/Is_Mainpage.html">
  <meta charset="ISO-8859-1">

  <title>Processing Details</title>
  <link rel="stylesheet" type="text/css" href="css/MF_job_failTable.css">
</head>

<body>

  <button onclick="myFunction()">Click me</button>

  <script>
    function myFunction() {
      document.getElementById("mymetatag").setAttribute("content", "5;URL=http://google.co.in");
    }
  </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)