通过javascript动态更改元标记内容
我想使用javascript动态更改元标记内容,即刷新率和url。使用按钮启用javascript功能。尝试了3种选择,但都不起作用。请帮忙 谢谢,阿姆雷斯通过javascript动态更改元标记内容,javascript,html,meta-tags,Javascript,Html,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_M
<!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>
处理细节
点击我
函数myFunction(){
var m=document.createElement('meta');
m、 名称='说明';
m、 id='mymetatag';
m、 内容='5;URL=http://google.co.in';
m、 HTTP-EQUIV='refresh';
文件.标题.附件(m);
}
我看起来您误用了MetaTag的功能,JS不会在请求之间保存状态。顺便说一句,您可以使用javascript本身进行重新加载/重定向 这对我很有用。
问题可能是您尝试了第一个不起作用的代码,并使用HTML注释
而不是Javascript注释对代码进行了注释:/[…]
或/***[…]*/
处理细节
点击我
函数myFunction(){
document.getElementById(“mymetatag”).setAttribute(“内容”,“5;URL=http://google.co.in");
}
是,这在web浏览器中工作。我在EclipseTomcat服务器中进行了尝试,但不起作用。谢谢兄弟。