Go Back   CodingForums.com > :: Client side development > General web building > Building for mobile devices

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-21-2011, 02:31 AM   PM User | #1
Celestial
New Coder

 
Join Date: Jan 2011
Location: Space
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Celestial is an unknown quantity at this point
Mobile Browsing

I was thinking of making a mobile optimized version of my website but I'm stuck on how the site can tell if it's a mobile device that's browsing, I assume it would be similar to the standard browser IF like:
Code:
<!--[if IE]>Things here.<![endif]-->
So i was just wondering what I would use to make it recognize a mobile browser and if there was a few codes for certain devices such as iPad and Android.

Last edited by Celestial; 06-22-2011 at 02:29 AM.. Reason: Resolved.
Celestial is offline   Reply With Quote
Old 06-21-2011, 04:50 AM   PM User | #2
Celestial
New Coder

 
Join Date: Jan 2011
Location: Space
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Celestial is an unknown quantity at this point
Quote:
Originally Posted by lightways View Post
no i think that could not be possible in mobile phones
It is... And thank you for all those pointless links.
Celestial is offline   Reply With Quote
Old 06-21-2011, 06:49 AM   PM User | #3
eberdome
Regular Coder

 
Join Date: Dec 2010
Location: California
Posts: 193
Thanks: 28
Thanked 8 Times in 8 Posts
eberdome is an unknown quantity at this point
stick this into your root .htaccess file

Code:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=mredir:0:www.example.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
RewriteCond %{HTTP_HOST}          !^m\.
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
RewriteRule ^ http://www.example.com/mobile [R,L]
change www.example.com on Line 4 to your domain name. On the last line, change to your mobile website! Anytime someone views your site from a mobile device they will be forwarded to the domain name you specify on the last line!
__________________
"The problem with troubleshooting is that trouble shoots back."

Last edited by eberdome; 06-21-2011 at 06:51 AM..
eberdome is offline   Reply With Quote
Users who have thanked eberdome for this post:
Celestial (06-22-2011)
Old 07-08-2011, 08:33 PM   PM User | #4
Celestial
New Coder

 
Join Date: Jan 2011
Location: Space
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Celestial is an unknown quantity at this point
Quote:
Originally Posted by eberdome View Post
stick this into your root .htaccess file

Code:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=mredir:0:www.example.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
RewriteCond %{HTTP_HOST}          !^m\.
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
RewriteRule ^ http://www.example.com/mobile [R,L]
change www.example.com on Line 4 to your domain name. On the last line, change to your mobile website! Anytime someone views your site from a mobile device they will be forwarded to the domain name you specify on the last line!
There appears to be a problem with this code, the site gets stuck on a loop of refreshes from it and I can't work out why. Any help?
Celestial is offline   Reply With Quote
Old 07-19-2011, 04:09 PM   PM User | #5
Apostropartheid
The Apostate


 
Apostropartheid's Avatar
 
Join Date: Oct 2007
Posts: 3,215
Thanks: 16
Thanked 265 Times in 263 Posts
Apostropartheid is on a distinguished road
No, browser sniffing is an awful, outdated way to do this.

You may provide mobile CSS by using this media query:

Code:
<link media="only screen and (max-device-width: 480px)" href="mobile.css" type="text/css" rel="stylesheet" />
__________________
Blog | Twitter
Useful links: W3C HTML Validator | W3C CSS Validator | HTML 5 Guide
CF: HTML & CSS Resources/Tutorials Thread | HTML & CSS Posting Rules and Guidelines
Remember: no link, no code, no help!
Apostropartheid is offline   Reply With Quote
Old 07-31-2011, 08:51 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
there is special meta for ios devices. many of the same also work on android.
till, these are mostly for decorating shortcuts, except for the scaling markup; it's important to nail for a proper user experience. needless scrolling makes mobile suck.

use special css for mobile and sniff mobile stuff in js using tools like modernizer or ad-hoc detection.


scale back on image use; its cost user's money and slows down the page considerably.
you can clobber any existing background-image urls using more specific selectors to declare background:none; ...

emphasize features of the site that are likely to be used by someone on a small screen or in an on-the-go situation. for example if you're an organization, don't blather about your history on the landing page, throw a menu in my face, preferably something that offers simple single word options like [news, events, search, sections, about]...


bottom line: you don't have as much room to look pretty or do fancy stuff.
people don't want that. they want to get in and out as quickly as possible cause it a PITA using a mobile browser. the less painful you make it, they more they will love you.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:26 AM.


Advertisement
Log in to turn off these ads.