【问题标题】:How to auto re-direct from other url?如何从其他网址自动重定向?
【发布时间】:2018-03-13 10:04:01
【问题描述】:

我正在写一个 condizionale 自动重定向 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 html css url-redirection dreamweaver


    【解决方案1】:

    在纯 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>
    

    【讨论】:

    • 如果我尝试使用: 无论如何都没有用跨度>
    • 您不能将元标记放在脚本块中。这不是它的工作方式。元标记应该在头标记内,您可以添加一个脚本标记,其中包含将要执行的代码,但只能在其中包含 Javascript。 &lt;head&gt; &lt;script&gt; if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { window.location= "organization.org/mobile/index_mobile.htm"; } &lt;/script&gt; &lt;/head&gt;
    • 哦...这就是原因。非常感谢!
    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 2022-06-29
    • 2017-07-12
    • 2018-10-25
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多