Detect iPad with javascript

  1. Home
  2. Knowledge Base
  3. WP Techniques
  4. Detect iPad with javascript

We created and maintain an intranet website for an electric utility (of whom I work for they pay my bills).  The site is accessed by personnel with iPads, and it contains some flash content (AccuWeather Accunet and Open Flash Chart). As you may already know flash is not supported by Apples Safari browser. We wanted to detect if the user was accessing the site with an iPad. If they are we use jQuery to alter the HTML code, removing the flash content and display a message Some content not available, your device does not support Flash. Of course we could replace the HTML with alternative content rather than the pat message, but for our needs this is what weve done.

First we use one line of javascript to detect if the user agent is an iPad.

Then we use jQuery to replace the HTML, where necessary, with our message using the html() function. Exampled below, were replacing the HTML if a <div> with an id of AccuWeather, with our message.

Our stance on Adobe Flash, we fully support the new HTML5 and CSS3 standards, and are not fans of Flash. Nor are we fans of Adobes new product Edge. We prefer to hand code, its usually much lighter and more understandable than code from a WYSIWYG.

Was this article helpful?

Related Articles

Leave a Reply