Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使一个超链接提供不同的页面?_Html - Fatal编程技术网

Html 如何使一个超链接提供不同的页面?

Html 如何使一个超链接提供不同的页面?,html,Html,我正在尝试设置一个超链接,每次单击一个URL列表,它都会随机打开一个不同的网页。有人知道要实现这一点,首先应该使用什么函数吗?像这样 <!DOCTYPE html> <html> <head> <script> var links = ['http://google.com', 'http://facebook.com'] function GoToSomeAddress() { window.open(links[getRandomIn

我正在尝试设置一个超链接,每次单击一个URL列表,它都会随机打开一个不同的网页。有人知道要实现这一点,首先应该使用什么函数吗?

像这样

 <!DOCTYPE html>
<html>
<head>
<script>
var links = ['http://google.com', 'http://facebook.com']
function GoToSomeAddress() {
    window.open(links[getRandomInt(0, 1)]);
}

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
</head>
<body>
The content of the body element is displayed in your browser.
<a href="" onclick="GoToSomeAddress();return false;">Take me on an adventure</a>
</body>

</html>

到目前为止你做了什么?一个很好的开始功能?有一个非常常用于begin,试试看,也许可以用JavaScript或服务器端脚本(如PHP等)完成。但不仅仅是用html。getRandomInt应该获得链接大小并使用它们,不需要参数。这很完美,谢谢!我在网上找了一个这样的例子,但没有找到。@O.Rares这是Mozilla为随机数范围提供的代码,显然你可以重构和移动,但这是基本的模板。