开发者

Classic View/Mobile View Switch?

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?

Our normal website is at:

us.companyname.com/

Our mobile website will be at:

us.companyname.com/mobile

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.

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.


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.

Something like this:

$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
}


Would something like this work:

  • When a user visits http://us.companyname.com from a mobile device, use JavaScript to redirect them to http://us.companyname.com/mobile.

  • On the mobile site, provide a link to the classic view at http://us.companyname.com?noredirect=true

All you'd have to do differently is wrap the window.location redirection code on the main page inside an if statement that makes sure the noredirect flag isn't set to true. The only challenge would be isolating the noredirect query string, but this Stack Overflow question might help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜