Javascript 如何在html/js中自动重定向到数组中的随机网站?
我更改了JavaScript变量提供给的方式。 这只是兰德,而不是&grave${rand}&grave 我还删除了unmatched closing},并添加了匹配的closingJavascript 如何在html/js中自动重定向到数组中的随机网站?,javascript,html,Javascript,Html,我更改了JavaScript变量提供给的方式。 这只是兰德,而不是&grave${rand}&grave 我还删除了unmatched closing},并添加了匹配的closing 代码看起来不完整。您遇到了哪些错误?需要关闭该脚本标记,并在末尾删除额外的}。使用浏览器控制台检查错误您可能需要window.location.href=rand <h1>heelo</h1> <script type ="text/javascript"> //this
代码看起来不完整。您遇到了哪些错误?需要关闭该脚本标记,并在末尾删除额外的}。使用浏览器控制台检查错误您可能需要window.location.href=rand
<h1>heelo</h1>
<script type ="text/javascript">
//this all should redirect but does not
alert('You are being redirected to random website')
var responses = ["https://www.google.com", "https://www.youtube.com"]
var rand = responses[Math.floor(Math.random() * responses.length)];
window.location.replace(`${rand}`)
}
<h1>heelo</h1>
<script type ="text/javascript">
alert('You are being redirected to random website')
var responses = ["https://www.google.com", "https://www.youtube.com"]
var rand = responses[Math.floor(Math.random() * responses.length)];
window.location.replace(rand)
</script>