[英]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.