如何将randString的值传递给URL
? URL = randString
不起作用。
<!DOCTYPE html>
<html>
<body>
<h1 id ="test">s1</h1>
<script>
var str1 = "http://www.vofoo.ru/reklam1.html";
var str2 = "http://www.viewtubes.ru/reklam1.html";
var str3 = "http://nofnof.xyz/reklam1.html";
var array = [str1, str2, str3];
var randString = array[Math.floor(Math.random()*array.length)];
document.getElementById("test").innerHTML = randString;
</script>
<META HTTP-EQUIV=REFRESH CONTENT="1; URL=document.getElementById(test).value">
</body>
</html>
关闭脚本代码后,URL
无法识别randString
答案 0 :(得分:2)
为什么在JS本身可以使用meta?
发表声明:
window.location.href = randString;
像这样:
var str1 = "http://www.vofoo.ru/reklam1.html";
var str2 = "http://www.viewtubes.ru/reklam1.html";
var str3 = "http://nofnof.xyz/reklam1.html";
var array = [str1, str2, str3];
var randString = array[Math.floor(Math.random()*array.length)];
document.getElementById("test").innerHTML = randString;
window.location.href = randString;
答案 1 :(得分:0)
您可以使用javascript
将属性设置为meta
标记。动态。
但请确保meta
代码必须位于head
的{{1}}部分。
我不知道你为什么要html
meta
。您可以使用简单的refresh
执行此操作。
希望此代码段可以帮助您javascript
刷新
meta
var str1 = "http://www.vofoo.ru/reklam1.html";
var str2 = "http://www.viewtubes.ru/reklam1.html";
var str3 = "http://nofnof.xyz/reklam1.html";
var array = [str1, str2, str3];
var randString = array[Math.floor(Math.random()*array.length)];
document.getElementById("test").innerHTML = randString;
var metaTag = document.getElementById("meta-refresh");
metaTag.setAttribute("content", "1;URL=" + randString);
console.log(metaTag.getAttribute("content")); //just to check URL is attached to meta tag.
答案 2 :(得分:0)
您的目标似乎是使用元标记重定向。单击h1后,我已将刷新停止到60秒和10秒。顺便说一句,元总是属于头脑。
<强>段强>
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV=REFRESH CONTENT="60;" />
</head>
<body>
<h1 id="test">s1</h1>
<p>Click title<sup>▲▲▲</sup>and wait 10 seconds</p>
<script>
//You can use window.location to the same effect
var here = window.location;
var str1 = "http://www.msn.com";
var str2 = "http://www.w3schools.com";
var str3 = "http://bing.com";
var test = document.getElementById('test');
var meta = document.querySelector('meta');
var array = [str1, str2, str3];
var randString = array[Math.floor(Math.random() * array.length)];
test.textContent = randString;
test.onclick = function() {
meta.setAttribute("content", "10; " + randString);
}
</script>
</body>
</html>