【发布时间】:2018-08-12 15:15:28
【问题描述】:
我有以下代码,我想将其与一个居中对齐的大按钮一起使用,以将访问者随机重定向到网站的一组 URL:
<html>
<head>
<script type="text/javascript">
<!--
// Create an array of the links to choose from:
var links = new Array();
links[0] = "http://www.google.com/";
links[1] = "http://www.bing.com/";
links[2] = "http://www.yahoo.com/";
links[3] = "http://www.apple.com/";
function openLink() {
// Chooses a random link:
var i = Math.floor(Math.random() * links.length);
// Directs the browser to the chosen target:
parent.location = links[i];
return false;
}
//-->
</script>
</head>
<body onload="openLink();">
</body>
</html>
我应该如何调整上面的代码来实现这一点?感谢您的帮助。
【问题讨论】:
-
应该是window.location.replace("url") 或者window.location = "url"
-
window.location.href不仅仅是window.location
标签: javascript html url redirect