6

Has anyone figured out a good way to detect if the client's browser is a Samsung phone. I'm specifically looking for Samsung S3 And Note 2, but if it catches S2 and Note 1 or other Samsung phones I can live with that. Something that is future proof (i.e. likely to work with S4 / Note3 is obviously ideal).

There seems to be no straight-forward way to do this like there is with iPhones, but with the large S3 and Note2 user base we would like to customize for those devices.

I'm aware that not all S3's have the same user agent (http://stackoverflow.com/questions/11282944/what-is-the-samsung-s3-user-agent)

And if someone has set there phone to PC version then I don't expect to catch these (http://stackoverflow.com/questions/11597940/android-phone-browser-detection)

I realize this is likely a problem with no good solution.

SemanticZen
  • 1,061
  • 13
  • 21
  • 1
    Why do you want to do that? User agents are at best unreliable for detecting browsers and devices. – RobG Dec 05 '12 at 06:18
  • Yes, in a perfect world we would never look at user agents but alas... to improve the user experience we give iPhones and Androids phones slightly different features and testing devices has demonstrated that Samsung is a level above HTC, LG, etc. For some features I can use feature detection... – SemanticZen Dec 05 '12 at 06:44
  • You don't need a perfect world. Design for supported features, everyone else manages it so you can too. UA sniffing is an ancient and flawed strategy that was discarded many years ago. Each time a new browser with issues comes along, you must write yet another sniff and yet another buggy fork. Use feature detection with sensible fallback (usually to basic HTML) and your life (and your customers' lives) will be very much easier. :-) – RobG Dec 05 '12 at 23:24
  • Sounds great Rob, so how do I detect if a browser supports a time picker? – SemanticZen Dec 06 '12 at 07:50
  • What type of timepicker? A browser based one? If you are referring to an input `type=time`, I wouldn't bother. They are poorly supported at present, a plain input and screen hint to specify the format you want will be far more robust. If you are using a library and plugin, ask the author. – RobG Dec 06 '12 at 14:54

2 Answers2

11

Detect Samsung Phone or Tablet default browser

if(navigator.userAgent.match(/SAMSUNG|SGH-[I|N|T]|GT-[I|P|N]|SM-[N|P|T|Z|G]|SHV-E|SCH-[I|J|R|S]|SPH-L/i))  {
    alert("it's Samsung default browser");
    // your code for Samsung goes here
}

This regex covers almost all Samsung mobile devices except Samsung Galaxy Nexus, Please verify.

Community
  • 1
  • 1
Anulal S
  • 5,824
  • 5
  • 21
  • 31
1

It's obviously very hard to detect only a Samsung phone, but if you check here, and check back to the User Agent question in your question here, you'd notice that the User Agent depends on the phone model.

Limiting to just the GS3, there are plenty of model numbers, such as GT-I9300[T], SHV-E210K/L/S, SGH-T999[v], SGH-I747[m], SGH-N064 (SC-06D), SCH-R530, SCH-I535, SPH-L710, GT-I9305[T], GT-I9308

I'm not a web developer, I'm not sure how you would go about detecting that certain part of the User Agent, but if you can adapt your code for every model of the GS3, I'm assuming that would work well. Same goes with the model numbers of the Note 2, and when they come out, the GS4/Note 3.

Community
  • 1
  • 1
lmcintyre
  • 98
  • 6