views:

49

answers:

1

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

BTW, I am using JQuery.

+3  A: 
if (navigator.userAgent.indexOf("myapp") !== -1) {
  alert("hi");
}

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

Eli Grey
+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.
Justin Johnson