繁体   English   中英

如何重定向“桌面桌面”?

[英]How to redirect a “Desktop Desktop”?

我的网站有两个版本。 桌面和移动版本。

当用户通过智能手机访问我的网站时,我将其指向“移动版” - >“m.mywebsite.com”。

为了实现它,我正在使用名为Mobile Detect的项目

到现在为止还挺好。

在“移动版”中,有一个按钮(“切换到桌面版”),重定向到“桌面版”。 问题是在“移动版”中,当我点击“切换到桌面版”按钮时,它会进入循环状态。

例如:

--->点击按钮“切换到桌面版”;
--->页面指向“www.mywebsite.com”;
--->页面完成刷新;
--->由于用户在智能手机上,脚本再次加载,用户被重定向到“m.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>

设置链接的地址

<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'))

这样, 只有在没有真正的force_desktop变量用户使用移动设备时,移动设备才会加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM