经典视图/移动视图切换?
我正在使用 jQuery Mobile 框架构建公司网站的一个版本。虽然通过 JavaScript 重定向来让移动设备用户访问我们的移动网站相当容易,但我也不想阻止人们查看经典网站。
实现这一目标的最佳方法是什么?
我们的正常网站位于:
us.companyname.com/
我们的移动网站位于:
us.companyname.com/mobile
有一些限制,因为我们不持有域名,而我们的英国同行持有域名,所以什么都可以做在 companyname.com 级别需要一些耐心。基本上,如果来自北美的任何人访问companyname.com,他们都会自动重定向到us.companyname.com。
我确实可以完全访问我们的网站(在我来到这里之前,主要是用 PHP 和表达式引擎编写的),并且只要我不搞砸任何事情,我就可以自由地做任何事情。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,这样的事情我不会用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.
Something like this:
像这样的事情会起作用吗:
当用户从 a href="http://us.companyname.com" rel="nofollow noreferrer">http://us.companyname.com 访问时移动设备,使用 JavaScript 将其重定向到 http://us.companyname.com/mobile。< /p>
在移动网站上,提供经典视图的链接:http://us.companyname。 com?noredirect=true
您所要做的就是将主页上的
window.location
重定向代码包装在if
语句,确保 noredirect 标志未设置为 true。唯一的挑战是隔离 noredirect 查询字符串,但是这个 Stack Overflow 问题可能会有所帮助。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 anif
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.