Browser detection (is bad, absolutely, but)


/ Published in: JavaScript
Save to your folder(s)

Browser detection is bad, absolutely.
But sometimes you need to display the inscription "you are using Opera browser" (or Chrome, FF, MSIE, Safari), or display the icon. You also need not be deceived if the user sets in the properties of "Mask as " a different browser.


Copy this code and paste it in your HTML
  1. var browser = (
  2. /*@cc_on!@*/ 0 ? 'msie' :
  3. window.chrome ? 'chrome' :
  4. window.opera ? 'opera' :
  5. window.MouseScrollEvent ? 'gecko' :
  6. window.WheelEvent ? 'safari' :
  7. 'unknown'
  8. );
  9.  
  10. alert(browser)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.