views:

172

answers:

2

I got this for IE browsers,

var IE = /*@cc_on!@*/false;

if (IE) {
    // IE.
} else {
    // Others.
}

but how would i do the same for iphone/ipad/mobiledevices? (do not want to redirect to another page on any mobile devices)

+4  A: 

You may want to check the user agent string as follows:

var userAgent = navigator.userAgent;

if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
   // iPad or iPhone
}
else {
   // Anything else
}
Daniel Vassallo
thank you~ it's working perfectly
A: 

That should be a bit of a problem because every app makes its own Header. My apache server gets this as Browser: [APPNAME]/1.0_CFNetwork/459_Darwin/10.3.0

You could search for Darwin, but i don't know if this is waterproof.

A JS-Snippet should look like that:

if (navigator.userAgent.indexOf("Firefox") != -1){ document.write('You're using Mozilla Firefox'); }

greets Simon

Simon
It's probably best not to check for "Darwin"; Darwin is the system that runs not only iPhone OS, but also Mac OS X. http://en.wikipedia.org/wiki/Darwin_(operating_system)
icktoofay