問題描述
所以我正在開發我正在做的網站的移動版本,并且到目前為止,我將移動網站內容從其主要對應物主站點中提取.
So I'm working on the mobile version of a site I'm doing, and so far, I'm pulling the mobile sites content from its main counterpart, the main site.
當我研究一些移動網站時,我注意到很多網站都有查看完整網站"鏈接.
As I study some mobile sites out there, I notice a lot of em have a "view full site" link.
現在我計劃通過檢查屏幕寬度等在主站點的標題標簽中通過 .js 重定向移動訪問者......(不確定這是否是最好的方法,但到目前為止我腦子里最簡單的方法))(但也歡迎提出建議)但是像這樣
Now I plan on redirecting the mobile visitors via .js in the header tag on main site via a check for screen width etc...(not sure if its the best way but so far the easiest on my brain))(but suggestions also welcome) but something like this
if (screen.width<=XyZ||screen.height<=XyZ) //example iphone size lets say 320x480
window.location.replace("mobile site link here.")
我不知道這是否是最好的方法,但在虛擬測試中,它適用于 iPhone、一些朋友 Droids 和一個黑莓.但它有效.
Again I dont know if this is the best way but, on dummy tests, it works on iPhone, some friends Droids, and one Blackberry. But it works.
無論如何,所以我的問題是,如果我在每個頁面上都進行此檢查...我怎么可能有查看完整站點"選項?
Anyways, so my question is, if i do this check on every page...how can I possible have a "view full site" option?
推薦答案
使用 PHP 通過 $_SERVER['HTTP_USER_AGENT']
檢測移動用戶.JavaScript 檢測可能不可靠,因為許多移動瀏覽器不支持 JS.查看完整站點"將設置 cookie 以拒絕可檢測到的移動站點.使用 cookie 來跟蹤用戶的偏好.
Use PHP to detect mobile users through $_SERVER['HTTP_USER_AGENT']
.
JavaScript detection may not be reliable, because many mobile browsers do not support JS.
A "View Full Site" will set a cookie to reject mobile site, which is detectable.
Use cookies to keep track of your user's preferences.
在骨架中
<?php
if (isset($_COOKIE['nomobile'])) {
$style = "normal";
} else {
if (preg_match('/iPhone|(...etc...)/', $_SERVER['HTTP_USER_AGENT'])) {
$style = "mobile";
} else {
$style = "normal";
}
}
對于查看完整站點"頁面:
For the "View Full Site" page:
<a href="fullsite.php">Full Site</a>
fullsite.php
<?php
setcookie('nomobile', 'true');
header('Location: index.php');
?>
這篇關于“查看完整站點"移動站點選項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!