【问题标题】:make a redirect button in html with javascript用javascript在html中制作一个重定向按钮
【发布时间】:2018-02-03 16:16:41
【问题描述】:

这是我尝试使用并嵌入到 Google 协作平台页面中的代码:

<!DOCTYPE html>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Please follow the link below</title>
    <script>
    var urls = [
        "http://www.kittenwar.com/",
        'http://heeeeeeeey.com/',
        'http://eelslap.com/',
        'http://www.staggeringbeauty.com/',
        'http://www.omfgdogs.com/',
        'http://burymewithmymoney.com/',
        'http://www.fallingfalling.com/',
        'http://ducksarethebest.com/',
        'http://www.republiquedesmangues.fr/',
        'http://www.trypap.com/',
    ];

    function goSomewhere() {
        var url = urls[Math.floor(Math.random()*urls.length)];
        window.location = url; // redirect
    }
</script>
</head>

<body>

</body>



</html>

如何进行这项工作,以便在我的 Google 协作平台页面中出现一个按钮,该按钮会随机将您分配到列出的链接数组之一?

【问题讨论】:

    标签: javascript html redirect random url-redirection


    【解决方案1】:

    通过添加一个简单的按钮并调用 javascript 函数。您需要在您的 google 站点帐户中进行一些调整。您可以参考此链接在您的帐户中进行相应的更改。

    http://www.thelandscapeoflearning.com/2014/05/did-you-know-google-sites-no-longer.html

    https://help.mofuse.com/hc/en-us/articles/226313408-Redirect-Setup-Google-Sites

     var urls = [
          "http://www.kittenwar.com/",
          'http://heeeeeeeey.com/',
          'http://eelslap.com/',
          'http://www.staggeringbeauty.com/',
          'http://www.omfgdogs.com/',
          'http://burymewithmymoney.com/',
          'http://www.fallingfalling.com/',
          'http://ducksarethebest.com/',
          'http://www.republiquedesmangues.fr/',
          'http://www.trypap.com/',
        ];
    
        function goSomewhere() {
          var url = urls[Math.floor(Math.random() * urls.length)];
          window.location = url; // redirect
        }
    <!DOCTYPE html>
    <html lang="en-US">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>Please follow the link below</title>
    </head>
    
    <body>
    <button onclick="goSomewhere();">Redirect</button>
    </body>
    
    </html>

    【讨论】:

    • 谢谢,太好了。但是,我发现该按钮不适用于 Google 协作平台本身的重定向。
    • 那是因为安全问题或某些原因。但是尝试一些不受欢迎的网站
    • help.mofuse.com/hc/en-us/articles/… 请参考这里更改您的谷歌网站的设置
    【解决方案2】:

    在正文中

    <button onclick="goSomewhere();">Click me</button>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 2014-08-20
      相关资源
      最近更新 更多