经典视图/移动视图开关? [英] Classic View/Mobile View Switch?

查看:90
本文介绍了经典视图/移动视图开关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Mobile框架构建公司网站的版本.尽管执行javascript重定向将移动设备的用户吸引到我们的移动网站相当容易,但我也不想阻止人们浏览经典网站.

I'm building a version of my company's website with the jQuery Mobile framework. While it'd be fairly easy to do a javascript redirect to get users of mobile devices to our mobile site, I don't want to stop people from being able to view the classic website either.

完成此任务的最佳方法是什么?

What's the best way to accomplish this?

我们的常规网站位于:

us.companyname.com/

us.companyname.com/

我们的移动网站将位于:

Our mobile website will be at:

us.companyname.com/mobile

us.companyname.com/mobile

有一些限制,因为我们不持有域名,我们的英国同行也拥有,所以在companyname.com级别上完成任何工作都需要一些耐心.基本上,如果来自北美的任何人来到companyname.com,他们都会自动重定向到us.companyname.com.

There are some limitations, as we don't hold the domain name, our UK counterparts do, so getting anything done at the companyname.com level takes some patience. Basically, if anyone from North America comes to companyname.com, they'll get automatically redirected to us.companyname.com.

我确实可以完全访问我们的网站(在我来这里之前,主要是用PHP& Expression引擎编写的),只要我不搞乱任何内容,我就可以自由地做任何事情.

I do have full access to our website (written primarily in PHP & Expression engine, before I was here), and I'm free to do whatever as long as I don't mess anything up.

推荐答案

首先,我不会使用Javascript/Query进行此类操作,如果用户未激活js,会导致什么情况?最好在服务器端执行此操作.

First, such things i would not do this with Javascript/Query, cause what is if the user has not activate js? It is better to do this server-side.

类似这样的东西:

$mobile = array("IPHONE", "IPAD");
$flagMobileVersion = false;
if($_SESSION['version']!="mobile"){ //happens only at first visit
for($i=0;$i<=count($mobile)-1;$i++){
    if(!strrpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $mobile[$i]))
    {
        $flagMobileVersion = true;
        break;
    }
}

if($flagMobileVersion) {
$_SESSION['version'] = "mobile";
Header("www.mydomain.net/mobile"); //on first Visit
}

这篇关于经典视图/移动视图开关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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