2

I want to target an ipad device in javascript. I know it is possible to do this with user agent string parsing. But this is easy to fake.

I also read that it's better to do a functionality test. like if(window.matchMedia) rather than if (userAgent.indexOf('ipad')) but still some functions exist in new browsers.

Is there anything that returns the word ipad in the browser ? thank you.

Hext0r
  • 157
  • 1
  • 6
  • Why are you trying to target iPad specifically? There are plenty of similar devices so discrimination doesn't seem to make much sense. – Quentin Jan 17 '12 at 17:12
  • hi thx for ur answer. but feature detection sometimes detect alot of new browsers. it is for a very specific client that want a special function executed for ipad users. – Hext0r Jan 17 '12 at 17:14

1 Answers1

3

Yes, prior to it's deprecation, navigator.platform could have done the job:

if( navigator.platform === 'iPad' ){

    // console.log('ipad')

}

Refer to https://stackoverflow.com/a/9039885/1029952 for more solutions

Pierre
  • 18,643
  • 4
  • 41
  • 62