javascript - 在 PHP 中使用解析的移动重定向

标签 javascript php html asp.net .htaccess

我有2页

index.php (For Desktop)

indexm.php (For Mobile)

我想通过检测屏幕分辨率大小来重定向它。

我正在尝试这段代码

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

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

注意:我不是在寻找标题位置

header('位置:indexm.php');

最佳答案

由于 php 是服务器端语言,因此无法使用 php 检测屏幕分辨率。您将不得不使用客户端脚本来实现所需的输出。

试试下面的javascript代码

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

关于javascript - 在 PHP 中使用解析的移动重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53279428/

相关文章:

javascript - 如何使用 easeljs-0.8.0.js 画线?(createJs)

javascript - 一次性设置 HTML 表格行

javascript - 刷新时随机数

php - 使用 db 类更新 Prestashop 数据库

javascript - 在具有最大高度的子元素中自动滚动

javascript - Reactjs:nth-​​child 的替代方案(jsx 无法正确构建 "child not defined")

php - 使用已建立的 PDO 连接与 Doctrine Master/Slave 连接

php - Mysql mysql_num_rows($result);备择方案

javascript - HTML5 "Canvas is null"

javascript - 我需要一个 safari/chrome bug 的解决方法,这个 bug 正在成为我的眼中钉