javascript - 使用分辨率的移动重定向
问题描述
我有 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 代码使其工作。
解决方案
对于 JavaScript:
更改window.location
为window.location.href = ('indexm.php');
对于 php,我认为使用 header 是最好的:
header('Location: indexm.php');
推荐阅读
- flutter - 检查约束并相应地返回正文
- android - 实时数据在更改片段时再次赋予旧值
- html - 如何将 Ionic 日期时间选择器定位到屏幕顶部?
- html - 缩放转换时列中的 CSS 元素位于上边框下方
- python - How can i remove double quotes in cmd title
- cassandra - Cassandra,如果集合包含值则删除
- android - 为小部件布局触发 Android 10 主题更新
- python - 无法 pipenv 从源代码(pypi)安装 confluent-kafka 1.4.0 - 似乎没有解决方法有效
- r - 关于 R 中 LFE 包中具有聚集标准误差的 p 值的问题
- powershell - Powershell 在 URL 中为 RestMethod 编码 JSON 数组