我的网站有两个版本。桌面和移动版本。
当用户通过智能手机访问我的网站时,我会将其指向“移动版本”-> "m.mywebsite.com“。
为此,我使用了一个名为移动检测的项目
到目前一切尚好。
在“移动版本”中有一个按钮(“切换到桌面版本”)重定向到“桌面版本”。问题是,在“移动版本”中,当我单击“切换到桌面版本”按钮时,它就会进入循环。
例如:
-点击“切换到桌面版本”按钮;
->页面指向"www.mywebsite.com";
->完成页面刷新;
我怎么能解决这个问题?
如何将用户重定向到智能手机的桌面版本?
我的代码:
<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
?>
<!DOCTYPE html>
<html>
<head>
<?php if( $detect->isMobile() ) : ?>
<script type="text/javascript">
window.location.href = "http://m.mywebsite.com.br";
</script>
<?php endif ?>
</head>
<body>
<div class="wrapper" style="height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column">
<h1>MOBILE VERSION</h1>
<a href="http://www.mywebsite.com.br">SWITCH TO DESKTOP VERSION</a>
</div>
</body>
</html>谢谢@Uriel你可以解决这个问题。现在这一页按我的要求运作。
<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<?php if( $detect->isMobile() && (!isset($_GET['force_desktop']) || $_GET['force_desktop'] == 'false')) : ?>
<?php if( $detect->isMobile() ) : ?>
<script type="text/javascript">
window.location.href = "http://m.mywebsite.com.br";
</script>
<?php endif ?>
<?php endif; ?>
</head>
<body style="padding: 0; margin: 0">
<div class="wrapper" style="height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column">
<h1>DESKTOP VERSION</h1>
</div>
</body>
</html>发布于 2016-10-20 20:02:56
设置链接的地址
<a href="http://www.mywebsite.com.br">SWITCH TO DESKTOP VERSION</a>到地址http://www.mywebsite.com.br&force_desktop=true。
然后,在检查移动设备时,还要检查这个GET变量是否为false (或不存在):
if( $detect->isMobile() && (!isset($_GET['force_desktop']) || $_GET['force_desktop'] == 'false'))这样,如果没有真正的变量,那么移动将只加载,用户使用移动的和。
https://stackoverflow.com/questions/40163302
复制相似问题