I want to run a website which contains flash. Obviously flash elements won't work on iPhone, iPod and iPad. Due to this fact I would like to create a CSS file ONLY for these devices. I am mostly worried about iPad, as i can use @media screen
size properties for other two.
What I have so far is this:
var IS_IPAD = navigator.userAgent.match(/iPad/i) != null;
if(IS_IPAD) ({
url: href,
dataType: 'css',
success: function(){
$('<link rel="stylesheet" type="text/css" href="'+css/ipad.css+'" />').appendTo("head");
}
});
What is not working here?
you could do something like this:
var is_ios = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
which would return true or false.
then:
if(is_ios)
{
$('<link rel="stylesheet" type="text/css" href="css/ipad.css" />').appendTo("head");
};
UPDATE:
A different approach, instead of using userAgent detection, would be to test for browser support. You can do it with jQuery like this:
$('html').addClass(typeof swfobject !== 'undefined' && swfobject.getFlashPlayerVersion().major !== 0 ? 'flash' : 'no-flash');
This works in a "Modernizr" style way of adding a class to the html
tag of the document, so in your css you can do this:
html.flash .element {
/*Do something here if flash if enabled*/
}
html.no-flash .element {
/*Do something different here if flash if not available*/
}
Why not just this:
var is_ipad = navigator.userAgent.match(/iPad/i) ? true : false;
if(is_ipad)
$('<link rel="stylesheet" type="text/css" href="path/to/css.css" />').appendTo('head');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With