Classic View/Mobile View Switch?

2020-06-25 07:31发布

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.

2条回答
萌系小妹纸
2楼-- · 2020-06-25 07:46

Would something like this work:

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.

查看更多
何必那么认真
3楼-- · 2020-06-25 07:52

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
}
查看更多
登录 后发表回答