mobile recognition
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
mobile recognition
When I go to a website using a mobile device, they often can sense that and automatically redirect me to the mobile version of that site. Does anyone know how that is done? I have found that many people use their mobile devices (usually smartphones) as the only portal to the internet and don't even own a computer, per se.
Don
-
- Administrator
- Posts: 78481
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: mobile recognition
When you visit a website, your browser sends some information to that website, among which the so-called user agent. This is a text string that (usually) provides information about the browser and about the operating system. The website can use this information to adjust the web page, or to tell you that your browser/system isn't compatible with the website.
The user agent will inform the website if you're using a mobile device.
For example, IE11 on my Windows 8 computer sends the following user agent:
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
while Chrome on my Android phone sends
Mozilla/5.0 (Linux; Android 5.0.2; D5803 Build/23.1.A.0.726) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.111 Mobile Safari/537.36
which clearly indicates a mobile device.
The user agent will inform the website if you're using a mobile device.
For example, IE11 on my Windows 8 computer sends the following user agent:
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
while Chrome on my Android phone sends
Mozilla/5.0 (Linux; Android 5.0.2; D5803 Build/23.1.A.0.726) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.111 Mobile Safari/537.36
which clearly indicates a mobile device.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
Re: mobile recognition
Interesting... how do you find what the user agent says? Could I find that from my iPhone?
Don
-
- Administrator
- Posts: 78481
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 5StarLounger
- Posts: 889
- Joined: 25 Jan 2010, 16:26
- Location: Garden Grove, CA 92844 USA
-
- 5StarLounger
- Posts: 847
- Joined: 24 Jan 2010, 06:35
- Location: A Magic Forest in Deepest, Darkest, Kent
Re: mobile recognition
This is a major headache for developers and application support staff in ICT who are looking after systems which rely on the user agent to determine styles sheet usage or security definition.
I have been parachuted into a team as a technical bod to help them out with this very issue as the software they used, in previous versions of IE up to 10 the agent read something like this:
IE 7
Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)
IE 8
Mozilla/5.0 (compatible;MSIE 8.0; Windows NT 6.1)
IE 9
Mozilla/5.0 (compatible;MSIE 9.0; Windows NT 7.1)
IE 10
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1)
Which by doing a little string manipulation on that header you could get the value of the 29th letter in the string to obtain what version of IE you were using and then dynamically route you to the right CSS or scripts or redirect you. This was fine for applications developed prior to IE 11 whose UA string is similar to:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko
Which caused all amounts of trouble and cost for upgrades or linking to legacy applications.
I hope you can share my grief
* The user strings above are just a small sample of other UA strings
I have been parachuted into a team as a technical bod to help them out with this very issue as the software they used, in previous versions of IE up to 10 the agent read something like this:
IE 7
Mozilla/4.0 (compatible;MSIE 7.0;Windows NT 6.0)
IE 8
Mozilla/5.0 (compatible;MSIE 8.0; Windows NT 6.1)
IE 9
Mozilla/5.0 (compatible;MSIE 9.0; Windows NT 7.1)
IE 10
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1)
Which by doing a little string manipulation on that header you could get the value of the 29th letter in the string to obtain what version of IE you were using and then dynamically route you to the right CSS or scripts or redirect you. This was fine for applications developed prior to IE 11 whose UA string is similar to:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko
Which caused all amounts of trouble and cost for upgrades or linking to legacy applications.
I hope you can share my grief
* The user strings above are just a small sample of other UA strings
Jerry
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it
I’ll be more enthusiastic about encouraging thinking outside the box when there’s evidence of any thinking going on inside it
-
- 3StarLounger
- Posts: 318
- Joined: 23 Aug 2016, 07:43
- Location: Sri Lanka
Re: mobile recognition
Thank you Hans,
I learn new thing today!
Additionally can recognize mobile/tablet devices by considering screen width. In WordPress can be done it by simply installing and setting-up a plugin.
Simple Mobile URL Redirect: https://wordpress.org/plugins/simple-mo ... -redirect/
Otherwise you can use javascript or php to do the same thing in your website. See below sample javascript code:
I learn new thing today!
Additionally can recognize mobile/tablet devices by considering screen width. In WordPress can be done it by simply installing and setting-up a plugin.
Simple Mobile URL Redirect: https://wordpress.org/plugins/simple-mo ... -redirect/
Otherwise you can use javascript or php to do the same thing in your website. See below sample javascript code:
Code: Select all
<script type="text/javascript">
<!--
if (screen.width <= 800) {
window.location = "http://m.yourdomain.com";
}
//-->
</script>
-Sampath-