【问题标题】:How to redirect using Javascript on all WebPages如何在所有网页上使用 Javascript 进行重定向
【发布时间】:2022-07-12 14:55:32
【问题描述】:

我正在尝试复制此网站:https://pslk.net/testtest,它使用 javascript 而不是服务器端重定向重定向到 https://pastelink.net/testtest

我知道如何使用 .htaccess 进行重定向:

RewriteEngine on
RewriteRule ^(.*)$ https://google.com/$1 [R=301,L]

和 Javascript:

<script>
location.href = "https://example2.com" + document.location.pathname; 
</script>

但我想使用 javascript 而不是 htaccess 进行重定向。所以我的问题是:我应该将我的 javascript 代码放在哪里才能在所有网页上执行?

因为我试图将它放在 index.html 中,但它没有重定向。它只会在我访问 index.html 时重定向

例如,如果我访问此链接:example.com/test,它将重定向到 example2.com/test。但我不能只在我的网站上创建多个包含该 javascript 的文件夹我很累,网站的路径名上有多种组合,我不认为该网站使用该 javascript 重定向创建了多个文件夹:https://pslk.net/testtest2

对不起,我对此很陌生,谢谢。

【问题讨论】:

    标签: javascript html .htaccess


    【解决方案1】:

    你可以用timeout函数试试:

    <html>
       <body>
          <script>
             setTimeout(function(){
                window.location.href = 'https://stackoverflow.com';
             }, 3000);
          </script>
          <p>Redirect after 3 seconds.</p>
       </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 2017-08-09
      • 2011-01-13
      • 2013-04-04
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      相关资源
      最近更新 更多