“查看完整站点";移动网站选项 [英] "VIEW FULL SITE" mobile site option

查看:71
本文介绍了“查看完整站点";移动网站选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在开发我正在做的网站的移动版本,并且 到目前为止,我正在从主要网站(主要网站)中提取移动网站的内容.

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.

当我研究一些移动网站时,我注意到很多em都有查看完整网站"链接.

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和一个Blackberry上运行.但这有效.

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

这篇关于“查看完整站点";移动网站选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆