Can someone tell me how I can determine (using JavaScript etc.) what browser is being used to visit my site?
I want to redirect to a different page based on these scenarios:
- Wheater the user is browsing using Safari on the iPhone.
- Using IE on a desktop
- Using IE on a WP7 mobile device.
Thanks.
Can someone tell me how I can determine (using JavaScript etc.) what browser is being used to visit my site?
I want to redirect to a different page based on these scenarios:
- Wheater the user is browsing using Safari on the iPhone.
- Using IE on a desktop
- Using IE on a WP7 mobile device.
Thanks.
Share Improve this question asked Dec 28, 2010 at 18:07 Jimmy CollinsJimmy Collins 3,3045 gold badges41 silver badges58 bronze badges 4- You could do this in JavaScript but that won't really help you much, as you will need to store that information somewhere to get it. What server side language/s can you use? – Pekka Commented Dec 28, 2010 at 18:08
- Server side language is PHP - all I need to do is ensure I present the mobile version to users browsing on a mobile device. – Jimmy Collins Commented Dec 28, 2010 at 18:09
- include that information in your post next time. Also, add the PHP tag. – Brad Commented Dec 28, 2010 at 18:13
- 2 stackoverflow./questions/1005153/… stackoverflow./questions/3632165/… – Brad Commented Dec 28, 2010 at 18:14
1 Answer
Reset to default 6Check out the Javascript Navigator object: http://www.w3schools./js/js_browser.asp
alert(navigator.userAgent);
This script may help you for more plicated detection: http://www.quirksmode/js/detect.html
You should be handling these redirections server-side though. This is particularly true if you have a mobile version of your site. Most mobile browsers do support Javascript just fine, but there are quirks.
Server-side, you can send a redirect by sending the 302 status code, and the location:
header. See http://en.wikipedia/wiki/HTTP_location
Edit: Since you say that you need to detect mobile browsers now in your ments, just use this script: http://detectmobilebrowsers.mobi/