“查看完整站点"移动站点选项

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

问题描述

限时送ChatGPT账号..

所以我正在开发我正在做的网站的移动版本,并且到目前为止,我将移动网站内容从其主要对应物主站点中提取.

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模板网!

上一篇:如何在php中检查请求是来自手机还是电脑 下一篇:WooCommerce 通过属性查询获取产品

相关文章

最新文章