简体   繁体   English

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

[英]“VIEW FULL SITE” mobile site option

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.当我研究一些移动网站时,我注意到很多网站都有“查看完整网站”链接。

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现在我计划通过检查屏幕宽度等在主站点上的 header 标记中通过.js 重定向移动访问者......(不确定它是否是最好的方法,但到目前为止我的大脑最简单))(但也有建议欢迎)但是像这样

if (screen.width<=XyZ||screen.height<=XyZ) //example iphone size lets say 320x480
window.location.replace("mobile site link here.")

Again I dont know if this is the best way but, on dummy tests, it works on iPhone, some friends Droids, and one Blackberry.同样,我不知道这是否是最好的方法,但在虚拟测试中,它适用于 iPhone、一些朋友 Droids 和一个 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?无论如何,所以我的问题是,如果我在每一页上都做这个检查……我怎么可能有一个“查看完整站点”选项?

Use PHP to detect mobile users through $_SERVER['HTTP_USER_AGENT'] .使用 PHP 通过$_SERVER['HTTP_USER_AGENT']检测移动用户。 JavaScript detection may not be reliable, because many mobile browsers do not support JS. JavaScript检测可能不可靠,因为很多手机浏览器不支持JS。 A "View Full Site" will set a cookie to reject mobile site, which is detectable. “查看完整站点”将设置一个 cookie 来拒绝移动站点,这是可检测到的。 Use cookies to keep track of your user's preferences.使用 cookies 跟踪用户的偏好。

In skeleton在骨架

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

First, go to the following URL and download the mobile_detect.php file:首先,go 到下面的 URL 并下载 mobile_detect.php 文件:

http://code.google.com/p/php-mobile-detect/ http://code.google.com/p/php-mobile-detect/

Next, follow the instructions on the page, and upload the mobile_detect.php to your root directory, Insert the following code on your index or home page:接下来,按照页面上的说明,将 mobile_detect.php 上传到您的根目录,在您的索引或主页上插入以下代码:

    <?php
    @include("Mobile_Detect.php");
    $detect = new Mobile_Detect();
    if ($detect->isMobile() && isset($_COOKIE['mobile']))
    {
    $detect = "false";
    }
    elseif ($detect->isMobile())
    {
    header("Location:http://www.yourmobiledirectory.com");
    }
    ?>

You will notice that the above code is checking for a cookie called "mobile", this cookie is set when the mobile device is redirected to the mobile page.您会注意到上面的代码正在检查一个名为“mobile”的cookie,这个cookie是在移动设备被重定向到移动页面时设置的。 To set the cookie insert the following code on your mobile landing page:要设置 cookie,请在您的移动登录页面上插入以下代码:

    <?php
    setcookie("mobile","m", time()+3600, "/");
    ?>

View the full article at: http://www.squidoo.com/php-mobile-redirect查看全文: http://www.squidoo.com/php-mobile-redirect

It's not a best way, because very often JS aren't supported by mobile browsers.这不是最好的方法,因为移动浏览器通常不支持 JS。

You can use this function:您可以使用这个 function:

function its_mobile_browser($user_agent = '')
{
    if (empty($user_agent))
    {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        if (empty($user_agent)) return false;
    }

    if (stripos($user_agent, 'Explorer')!==false ||
        stripos($user_agent, 'Windows')!==false ||
        stripos($user_agent, 'Win NT')!==false ||
        stripos($user_agent, 'FireFox')!==false ||
        stripos($user_agent, 'linux')!==false ||
        stripos($user_agent, 'unix')!==false ||
        stripos($user_agent, 'Macintosh')!==false
    )
    {
        if (!(stripos($user_agent, 'Opera Mini')!==false
              || stripos($user_agent, 'WAP')!==false
              || stripos($user_agent, 'Mobile')!==false
              || stripos($user_agent, 'Symbian')!==false
              || stripos($user_agent, 'NetFront')!==false
              || stripos($user_agent, ' PPC')!==false
              || stripos($user_agent, 'iPhone')!==false
              || stripos($user_agent, 'Android')!==false
              || stripos($user_agent, 'Nokia')!==false
              || stripos($user_agent, 'Samsung')!==false
              || stripos($user_agent, 'SonyEricsson')!==false
              || stripos($user_agent, 'LG')!==false
              || stripos($user_agent, 'Obigo')!==false
              || stripos($user_agent, 'SEC-SGHX')!==false
              || stripos($user_agent, 'Fly')!==false
              || stripos($user_agent, 'MOT-')!==false
              || stripos($user_agent, 'Motorola')!==false
        )
        ) return false;
    }

    return true;
}

Or something better, lol:)或者更好的东西,大声笑:)

You can add a query string parameter to your website address such as ?fullsite=true and include the following in your if condition >您可以将查询字符串参数添加到您的网站地址,例如?fullsite=true并在您的 if 条件中包含以下内容 >

var fullsite = getQueryString()["fullsite"];
if (fullsite != "true" && (screen.height <= xyz || screen.width <= abc)) //now redirect

You'll need the following function access query string.您将需要以下 function 访问查询字符串。 I took it from here > JavaScript query string我从这里拿的 > JavaScript 查询字符串

function getQueryString() {
  var result = {}, queryString = location.search.substring(1),
      re = /([^&=]+)=([^&]*)/g, m;

  while (m = re.exec(queryString)) {
    result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
  }

  return result;
}

And in the link you can have >在链接中,您可以拥有 >

<a href="mysite.com?fullsite=true"> Show me Full Site </a>

=========== ===========

Saying that please take a look at CSS Media Queries.说,请看一下 CSS 媒体查询。 It may require changing a bit of your design architecture but it's pretty useful.它可能需要更改一些设计架构,但它非常有用。

Server-side detection is definitely the way to do this, as you have no guarantee of JS being available or even turned on.服务器端检测绝对是做到这一点的方法,因为您无法保证 JS 可用甚至打开。 A great PHP script for mobile detection is found here http://detectmobilebrowsers.mobi/ and it gets a lot of use around the web.在这里http://detectmobilebrowsers.mobi/找到了一个用于移动检测的出色 PHP 脚本,它在 web 周围得到了很多使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM