只允许从移动设备和平板电脑访问 [英] Allow access only from mobile and tablet devices

查看:112
本文介绍了只允许从移动设备和平板电脑访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户有非常具体的要求.他想阻止所有经典"计算机(台式/笔记本).

因此,如果我从iPhone,Android或平板电脑访问该网站,它将显示所有内容(我可以通过响应设计获得不同的分辨率).但是,当Mac,Windows或Linux(我知道Android也是基于gnu/linux;)的人访问网络时,他只会收到一条消息,指出该网络仅适用于移动设备"或类似taht. >

但是我不确定如何禁止" mac os,win,linux等.

可以使用javascript(jQuery)库,例如Modernizr或其他此类特定条件是否仅是移动设备"?

关于Windows 8 :(??p

我真的很感谢任何建议,因为我以前从未有过这样的要求?

解决方案

我认为您可以通过几种方式来做到这一点.

您要么通过javascript进行检查,但是如果有人关闭javascript,您将再次被搞砸,因为他们可以查看该网站:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
 // some code..
}

或者您可以通过modernizr进行检查,但是我不知道该如何在modernizr中进行操作,并且您还会遇到关闭javascript代码的问题,

或者您可以通过以下方式下载适合您情况的脚本:

http://detectmobilebrowsers.com/

您可以做的另一件事是检查屏幕分辨率,但是,我们又回到了JavaScript的情况.

My client has very specific request. He wants to block all "classic" computers (desktop/notebook).

So if I access the website from iPhone, Android or tablet it displays everything (the different resolutions I can hadle via responsive design). But when somebody from Mac or Windows or Linux (I know that Android is also based on gnu/linux ;) ) access the web, he gets only a message that "this web is only for mobile devices"or something like taht.

But I am not sure how to "ban" mac os, win, linux etc.

Could javascript(jQuery) library e.g. Modernizr or other do such specific condition "just mobile devices"?

What about Windows 8 :( ?

i am really thankful for any advice, because I have never had such request before?

解决方案

I think you could do this in several ways.

Either you check via javascript, but then you if somebody would turn off javascript you would be screwed again because they could take a look at the website:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
 // some code..
}

or you could check it via modernizr, but I don't know exactly how to do it in modernizr and you would also have the problem of turned off javascript code,

or you could download a script that is suitable for your case via:

http://detectmobilebrowsers.com/

another thing you could do is checking the screen resolution but, then we are back at the javascript case.

这篇关于只允许从移动设备和平板电脑访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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