javascript - 我如何调整此代码以在 Google 协作平台上运行?

标签 javascript html url redirect web

我目前正在尝试开发一个随机重定向按钮,我需要对以下代码进行两处调整:

<script>
<!--
/*
Random link button- By JavaScript Kit (http://javascriptkit.com)
Over 300+ free scripts!
This credit MUST stay intact for use
*/

//specify random links below. You can have as many as you want
var randomlinks=new Array()

randomlinks[0]="http://surveymonkey.com"
randomlinks[1]="http://typeform.com"
randomlinks[2]="http://dynamicdrive.com"
randomlinks[3]="http://cnn.com"
randomlinks[4]="http://www.geocities.com"

function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}
//-->
</script>
<form method="post">
<p><input type="button" name="B1" value="Continue" onclick="randomlink()"></p> </form>

上面的代码生成了一个按钮,在已发布的网站上单击该按钮似乎没有任何反应。如何使按钮真正 重定向?我还想将按钮的大小调整为大 5 倍并居中对齐。

感谢您的帮助。

最佳答案

它无法打开的原因是您的函数中使用了 .open 方法。

下面是使用 window.open 的新代码:

window.open(randomlinks[Math.floor(Math.random()*randomlinks.length)]);

要格式化按钮,您应该使用 CSS。

查看类似 this 的内容

关于javascript - 我如何调整此代码以在 Google 协作平台上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930545/

相关文章:

javascript - 如何从另一个页面获取值(value)

javascript - 解析ajax请求,返回页面为xml

javascript - 在 JavaScript 中将条件传递给 var

javascript - Mturk externalQuestion 与 jquery.ajax POST : Access-Control-Allow-Origin error

javascript - 如何从 jQuery 中的动画 div 获取宽度

javascript - 点击链接,div滑出,链接div滑入,点击关闭重新加载第一个div

html - Opera 和 HTML5 视频

jquery - 为什么 Chrome 无法正确处理使用 jQuery 添加的 flexbox 元素?

html - 显示来自 html5 音频流的当前歌曲信息(在 Meteor 应用程序中)

javascript - 如何使用单选按钮添加和删除 URL 中的字符? (Javascript)