Reputation: 3324
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?
Upvotes: 0
Views: 4639
Reputation: 1227
According to MSDN, Windows adds Tablet PC
to the browser user agent if it is a tablet.
I suggest not doing this via javascript, because as states above: if javascript is disabled, people will be able to visit your site.
Upvotes: 0
Reputation: 7536
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.
Upvotes: 1