Problem: I have found the following javascript to detect if it is IPhone and so on:
<script language=javascript>
function isApple(userAgent){
var iPhone = userAgent.match(/iPhone/i) !== null;
var Apple = userAgent.match(/Apple/i) !== null;
var Mac = userAgent.match(/Mac/i) !== null;
var iPod = userAgent.match(/iPod/i) !== null;
var iOS = userAgent.match(/iOS/i) !== null;
return iPhone || Apple || Mac || iPod || iOS;
}
// Use like this...
if(isApple(navigator.userAgent)){
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="/bootstrap/css/iphone.css">');
}
</script>
However, it does not work properly. It appears it affects desktop(non apple) and andriods with the css styling that should come affect only IPhones.
Not sure if there is a better approach. Any help would be appreciated
*****I am able to detect which device the user is using based on the following script:
var deviceType = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
alert(deviceType);
However, when I do the following so that if it is an iPhone, the css does not apply to the iPhones. The image is still disorted.
if(deviceType == 'iPad' || deviceType == 'iPhone'){
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', '<link rel="stylesheet" href="/bootstrap/css/iphone.css">');
}
and the following is the CSS I am using:
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-width: 991px) and (min-width: 768px){
#homepage .carousel .item {
/*height: auto !important;*/
margin-top: 115px !important;
}
}
@media screen and (max-width: 991px) and (min-width: 768px) and (orientation:landscape){
#homepage .carousel .item {
/*height: auto !important;*/
margin-top: 20px;
}
}
@media (max-width:961px) and (min-width: 768px) and (orientation:landscape){
#homepage .carousel .carousel-caption {
top: -20px !important;
}
}
/* Portrait and Landscape iphone*/
@media only screen
and (max-device-width: 480px)
and (orientation:portrait) {
#homepage .carousel .item {margin-top: 71px; height: 150px !important;}
#homepage .carousel .item img { max-width: 100%; height: auto; display: block; }
}
@media only screen
and (max-device-width: 480px)
and (orientation:landscape) {
#homepage .carousel .item { height: 250px !important; }
#homepage .carousel .item img { max-width: 100%; height: auto; display: block; }
}