问题遇到的现象和发生背景
不懂代码,希望在WordPress文章内,点击一个链接,随机跳转到不同的网址,在网上找到下面代码,前段时间测试,还是有效的,但是现在打算使用时,发现可以在新标签页打开,但是空白页,并没有随机打开其中的网址,请问下面代码有问题吗?另外不想暴露自己的网站,所以希望加上 rel="nofollow noopener noreferrer" 这段代码,应该加在哪个位置?
请修改下面或提供其他源代码,非常感谢!
<script language="javascript">
function test(){
var url=new Array();
url[0]="http://www.baidu.com";
url[1]="http://www.csdn.net";
url[2]="http://bbs.voc.com.cn";
var ints=parseInt(Math.random()*(url.length));
window.open(url[ints]);//本窗口打开
//window.location=url[ints];//新窗口打开
}
</script>
<a href="javascript:test()">test</a>