从javascript中的数组重新加载url

发布于 2024-12-06 13:06:31 字数 1061 浏览 1 评论 0原文

我正在为 chrome 扩展编写以下代码。基本上我希望它检查最初加载的页面,如果它与我的网站 st.mywebsite.com 匹配,它将执行代码。现在它不会检查并将执行任何加载的页面。我试图让它加载 http://st.mywebsite.com/?q= 加上数组中的术语。因此,每隔 X 秒/分钟,它将在数组中加载一个新术语并将其添加到 url http://st.mywebsite.com/?q= 有人可以帮忙吗?

if((window.location.hostname != "st.mywebsite.com")){
    window.onload = function() {
        terms = new Array("5d65sd", "95sd4s", "h2j4g8h", "c87e2dd", "e6e5f2g4", "3m5g5gv");

        min = 1;//minimum
        max = 60;//maximum
        randomnumber = Math.floor(Math.random() * (max - min + 1)) + min;

        var seconds = randomnumber;
        var timer;

        function countdown() {
          var container = document.getElementById('right');
          seconds--;
          if(seconds > 0) {
            container.innerHTML = '<p>Please wait <b>'+seconds+'</b> seconds.</p>';
          } else {
            window.location = 'http://st.mywebsite.com/?q='+terms;
          }
        }

        timer = setInterval(countdown, 1000);
    }
}

I am working on the following code for a chrome extension. Basically I want it to check the page that initially loads and if it matches my website st.mywebsite.com it will execute the code. Right now it doesn't check and will execute any pages that loads. I am trying to get it to load http://st.mywebsite.com/?q= plus the terms in the array. So every X number of seconds/minutes it will load a new term in the array and add it to the url http://st.mywebsite.com/?q=can anyone help?

if((window.location.hostname != "st.mywebsite.com")){
    window.onload = function() {
        terms = new Array("5d65sd", "95sd4s", "h2j4g8h", "c87e2dd", "e6e5f2g4", "3m5g5gv");

        min = 1;//minimum
        max = 60;//maximum
        randomnumber = Math.floor(Math.random() * (max - min + 1)) + min;

        var seconds = randomnumber;
        var timer;

        function countdown() {
          var container = document.getElementById('right');
          seconds--;
          if(seconds > 0) {
            container.innerHTML = '<p>Please wait <b>'+seconds+'</b> seconds.</p>';
          } else {
            window.location = 'http://st.mywebsite.com/?q='+terms;
          }
        }

        timer = setInterval(countdown, 1000);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城仅有旧梦在 2024-12-13 13:06:31

window.location 行,将其更改为 window.location.href

At the line you have window.location, change it to window.location.href

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文