How to set the ios bookmark icon in HTML

To set the ios bookmark icon in HTML you can use the following snippet.

Sample HTML

<link rel="apple-touch-icon" href="iOs_Icon.png"/>

If your icon is already glossy, you can prevent the device from adding its own gloss by using.

Sample HTML

<link rel="apple-touch-icon-precomposed" href="iOs_Icon.png"/>

How to detect a screen orientation change in Javascript

To detect a screen orientation change in Javascript you can use the following snippet.

Sample Javascript

window.addEventListener("orientationchange", function() {
	//0 = potrait
	//90 or -90 = landscape left or landscape right
}, false);

some devices do not fire the orientationchange event, try the resize event instead.

Sample Javascript

window.addEventListener("resize", function() {
	// check screen size (inner and outer!)	
}, false);

How to check if a userAgent is a mobile device in jQuery

To check if the userAgent is a mobile device in jQuery you can use the following snippet.
It will match the following:

  • • Android
  • • webOS
  • • iPhone
  • • iPad
  • • iPod
  • • BlackBerry

Sample jQuery

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/.test(navigator.userAgent) ) {
	// mobile device
} 
else 
{
	// other device
}