繁体   English   中英

如何自动从其他网址重定向?

[英]How to auto re-direct from other url?

我正在写一个条件自动重定向URL,但是它不起作用。 我尝试了两种方法:

<script>
      function mobileDevice()
        {
        $type = $_SERVER[‘HTTP_USER_AGENT’];
        if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)
        return true;
        else
        return false;
        }
        if(mobileDevice() == true)
        header(‘Location: https://www.organization.org/mobile/index_mobile.htm‘);
</script>

<script type="text/javascript">
      if (screen.width <= 414) {
        document.location = "index.htm";
        <script language=javascript>
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
       location.replace("https://www.organization.org/mobile/index_mobile.htm");
    }
          </script>
      }
    </script>

正如我尚未宣布的那样,没有一个有效,为什么?

在纯Javascript中,您应该分配值位置,而不要使用方法进行重定向。 replace方法不会在历史记录中保存url的更改。

window.location = "https://www.organization.org/mobile/index_mobile.htm";

另外,您在第二种方法中嵌套了两个标签。 正确的代码是:

<script type="text/javascript">
      if (screen.width <= 414) {
        document.location = "index.htm";
        if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
          location.replace("https://www.organization.org/mobile/index_mobile.htm");
        }
      }
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM