我的任务是构建一个脚本,让用户能够在网站的移动版和桌面版之间来回切换。使用媒体查询(大小方面)所有样式都可以正常工作,但是,当在移动设备上实现墨迹时,(在浏览器大小检查后通过隐藏潜水隐藏在桌面上)它会切换到桌面版本,但是当用户单击时在返回“移动”版本的链接上,它需要两次尝试才能呈现移动样式表。这是我的代码。
<?php //get the users choice and start or kill the session
$getWidth = $_GET["getWidth"];
if ($getWidth == "all"){
session_destroy();
} else if ($getWidth == "desktop") {
session_start();
$_SESSION['desktop'] = "1";
}
//get the current working page so the user comes back to where they were
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
//Change the div ID so the users either sees one link or the other
if(isset($_SESSION['desktop'])) {
$divID = "switchtodesktop";
} else {
$divID = "switchtomobile";
}
?>
CSS页面:
<?php
if(isset($_SESSION['desktop'])) {
?>
<link href='<?php echo $path;?>css/desktop.css' rel="stylesheet" type="text/css">
<?php } else { ?>
<link href='<?php echo $path;?>css/mq.css' rel="stylesheet" type="text/css">
<?php } ?>
包含所有页面上的链接的 Div:
<div id='<?php echo $divID;?>'>
<?php
if(isset($_SESSION['desktop'])) {
?>
<a href='<?php echo $pageURL;?>?getWidth=all'>SWITCH TO MOBILE VIEW</a>
<?php } else { ?>
<a href='<?php echo $pageURL;?>?getWidth=desktop'>SWITCH TO DESKTOP VIEW</a>
<?php } ?>
</div>
我正在拉我的头发,试图让它一键恢复!
任何帮助是极大的赞赏。
谢谢。