首页 > 解决方案 > 使用分辨率的移动重定向

问题描述

我有 2 页 index.php(用于桌面)和 indexm.php(用于移动)。我想通过检测屏幕分辨率大小来重定向它。我正在尝试这段代码

<script type="text/javascript">
    if (screen.width <= 720) {
        window.location = "indexm.php";
    } else {
        window.location = "index.php";
    }
</script>

我也在 PHP 中尝试相同的方法,

<?php 
  if (screen.width <= 720) {
      include "indexm.php";
  } else {
      include "index.php";
  }
?>

但是这两个代码都不起作用,请帮助我使用 PHP 或 JavaScript 代码使其工作。

标签: javascriptphpjqueryhtmlasp.net

解决方案


对于 JavaScript:

更改window.locationwindow.location.href = ('indexm.php');

对于 php,我认为使用 header 是最好的:

header('Location: indexm.php');

推荐阅读