detect mobile browser and javascript support
I want to detect if the request is coming from a mobile browser (i m using java/jsp)
Now when i access the page from my samsung mobile phone i get the user agent header as: -
SAMSUNG-GT-S5620/S5620DDJE1 SHP/VPP/R5 Dolfin/1.5 Nextreaming SMM-MMS/1.2.0 profile/MIDP-2.1 configuration/CLDC-1.1
should i check that the header contains iPhone,BlackBerry,Android,webOS,iPod,Samsung or there is some more simple way...
How can i make sure that the browser supports javascript 开发者_运维技巧and
by the way does mobile browsers suppport hashchange or anything js "advanced"
If javascript is not supported by the mobile browser then i would like to redirect to some simple page with a single form...
or i have to make a simple page for mobile browser such that it runs well with or without js support
thanks
You can use something like WURFL to see if the browser has some level of Javascript support.
You can't, however, tell if the browser has Javascript enabled or which Javascript features are supported by the particular version of the browser on that particular device.
You should, instead, use progressive enhancement in the browser to add Javascript-based functionality by testing for the specific functionality required.
Have you tried using something like Modernizr? In general you shouldn't detect browsers because there are so many of them and you just cannot know every feature of every version of every browser on every platform, not to even mention that you can't even be sure that the user agent header is right. You should detect features instead.
There are many more browsers and more incompatibilities on the mobile platforms than on the desktop. After trying to build portable websites for mobile browsers you'll actually start to love IE6 for it's compliance with standards. That's why I recommend using something like the jQuery Mobile to do the hard work of figuring out the differences and inconsistencies between platforms and giving you a nice and consistent API. Otherwise here's a list of platforms that you have to consider supporting: http://jquerymobile.com/gbs/
Using www.handsetdetection.com I would do a detection server side. If the browser is poor quality or unsophisticated then redirect them to the simple mobile page, if the browser is decent then send them to your mobile page.
The detection will be happening on your main site. To allow visitors to move from your mobile site back to your normal site check the http referrer. If the referrer is you mobile site then do not redirect them back.
Hope that helps.
Try this: (although this makes the detection from the client side)
<!DOCTYPE html>
<html>
<head> <title> going from here to the real page... </title> </head>
<body>
<noscript>
Javascript is disabled.
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourSite.com/yourStaticPage.html/">
</noscript>
<script type="text/javascript">
// most of smartphons support this orientation property:
if (typeof window.orientation !== 'undefined'){
window.location.replace("http://yourSite.com/yourMobilePage.html");
}
else {
window.location.replace("http://yourSite.com/yourDesktopPage.html");
}
</script>
</body>
</html>
精彩评论