无论您在哪里用鼠标单击该网站以在新选项卡中打开链接,每10个概率中的1个,我都希望创建一个脚本。
这是我到目前为止所拥有的
<a href="newwindow.html" target="_blank">New Window</A>
<a href="http://www.example.org" onclick="window.open('http://www.google.com','newwin');">click me</a>
<script type="text/javascript">
var random=Math.floor(Math.random()*11);
alert(random);
window.open("http://www.google.com","windowName");
</script>
我正在考虑一个不可见的div,当您单击它以使其消失时。
而且,当用户打开该链接后,我必须确保他不会第二次打开它,所以我必须进行会话。此步骤是可选的。
<script type="text/javascript">
document.body.onclick = function () {
var rand = Math.floor(Math.random()*10); // 0-9 randomly
if (rand === 0) {
window.open("http://www.google.com","_tab");
}
}
</script>
这呢?
<script type="text/javascript">
document.body.onclick = function () {
var rand = Math.floor(Math.random()*10); // 0-9 randomly
if (rand === 0) {
alert("1 in 10 chance!");
}
}
</script>