开发者

Determine which browser is being used to visit my site

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 mo开发者_如何学JAVAbile device.

Thanks.


Check out the Javascript Navigator object: http://www.w3schools.com/js/js_browser.asp

alert(navigator.userAgent);

This script may help you for more complicated detection: http://www.quirksmode.org/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.org/wiki/HTTP_location

Edit: Since you say that you need to detect mobile browsers now in your comments, just use this script: http://detectmobilebrowsers.mobi/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜