Jitendra Vyas
Jitendra Vyas

Reputation: 152627

How to prevent to load a javascript and css file on iOS and Android devices?

How to prevent to load a js file on iOS and Android devices? I'm making a website for all devices. I want to add some specific JavaScript+CSS effect only for desktop user not to iPhone,iPad and Android, Windows phone users. So can i stop to load some specific JavaScript and CSS files to load on specific devices.

Upvotes: 1

Views: 1157

Answers (4)

Simpleton
Simpleton

Reputation: 6415

Call your CSS files using media queries from within your JavaScript file.

Upvotes: 0

phemios
phemios

Reputation: 674

For css you should really try mediaqueries. For example, if you want to set css only for iPhone you can use:

/* Portrait */
@media screen and (max-width: 320px) {
    body { opacity: 1; }
}
/* Landscape */
@media screen and (min-width: 321px) and (max-width: 480px) {
    body { opacity: 0; }
}

But for desktop it's the same, you select what is your min-widh and max-width.

For Js, I advise you to read this: http://www.quirksmode.org/blog/archives/2010/08/combining_media.html

Upvotes: 0

Ross
Ross

Reputation: 14415

You can use the Yepnope library to conditionally load javascript files. http://detectmobilebrowsers.com/ has libraries to detect if the website is loaded onto a mobile. Therefore you can combine both.

Upvotes: 1

Jack
Jack

Reputation: 10993

You can try detecting the useragent and then dynamically loading the scripts/css you want.

Upvotes: 0

Related Questions