問題描述
所以我正在開發(fā)我正在做的網(wǎng)站的移動(dòng)版本,并且到目前為止,我將移動(dòng)網(wǎng)站內(nèi)容從其主要對(duì)應(yīng)物主站點(diǎn)中提取.
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.
當(dāng)我研究一些移動(dòng)網(wǎng)站時(shí),我注意到很多網(wǎng)站都有查看完整網(wǎng)站"鏈接.
As I study some mobile sites out there, I notice a lot of em have a "view full site" link.
現(xiàn)在我計(jì)劃通過檢查屏幕寬度等在主站點(diǎn)的標(biāo)題標(biāo)簽中通過 .js 重定向移動(dòng)訪問者......(不確定這是否是最好的方法,但到目前為止我腦子里最簡單的方法))(但也歡迎提出建議)但是像這樣
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 和一個(gè)黑莓.但它有效.
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.
無論如何,所以我的問題是,如果我在每個(gè)頁面上都進(jìn)行此檢查...我怎么可能有查看完整站點(diǎn)"選項(xiàng)?
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']
檢測移動(dòng)用戶.JavaScript 檢測可能不可靠,因?yàn)樵S多移動(dòng)瀏覽器不支持 JS.查看完整站點(diǎn)"將設(shè)置 cookie 以拒絕可檢測到的移動(dòng)站點(diǎn).使用 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";
}
}
對(duì)于查看完整站點(diǎn)"頁面:
For the "View Full Site" page:
<a href="fullsite.php">Full Site</a>
fullsite.php
<?php
setcookie('nomobile', 'true');
header('Location: index.php');
?>
這篇關(guān)于“查看完整站點(diǎn)"移動(dòng)站點(diǎn)選項(xiàng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!