Wednesday, April 6, 2011

How do I do this with the user agent?

If the user-agent includes the word "myapp", then alert('hi');

BTW, I am using JQuery.

From stackoverflow
  • if (navigator.userAgent.indexOf("myapp") !== -1) {
      alert("hi");
    }
    

    I recommend you don't do user-agent sniffing.

    Justin Johnson : +1 For the recommendation against sniffing. For the rest of the class: Instead of user-agent sniffing, *feature detection* should be used to determine the type of browser that you are dealing with.

0 comments:

Post a Comment