I have a scenario in which I need to detect whether the device is an iPod or iPhone. navigator.userAgent/navigator.platform doesn't have device information.
Here is what I use to detect iOS devices:
function is_little_ithing() {
return (navigator.userAgent.indexOf('iPod') > -1 ||
navigator.userAgent.indexOf('iPhone') > -1);
}
function is_big_ithing() {
return (navigator.userAgent.indexOf('iPad') > -1);
}
function is_ithing() {
return (is_little_ithing() || is_big_ithing());
}
Related
I want to used on JH Image Popup. - https://joomla-handbuch.com/en/downloads/jh-image-popup
I have check on IF conditions image popup was not loading in our Mobile Devices.
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
}else{
}
How to check PHP code using on Javascirpt?
$doc->addScript('colorbox-min.js');
$doc->addStyleSheet('colorbox.min.css');
And This file was not execute in mobile devices.?
Maybe you can check if a device is touchable or not:
function is_touch_enabled() {
return ( 'ontouchstart' in window ) ||
( navigator.maxTouchPoints > 0 ) ||
( navigator.msMaxTouchPoints > 0 );
}
if(is_touch_enabled()){
//Your code
}else{
//Your code
}
The following function which uses window.open doesn't work in Firefox mobile for iOS. Any ideas why?
https://jsfiddle.net/3z6ygk8w/
<button onclick="mapsSelector('47.91', '-122.02')">
Test
</button>
<script>
function mapsSelector(locationLatitude, locationLongitude) {
if /* if we're on iOS, open in Apple Maps */
((navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPad") != -1) ||
(navigator.platform.indexOf("iPod") != -1))
window.open("maps://maps.google.com/maps?daddr="+locationLatitude+","+locationLongitude+"&ll=");
else /* else use Google */
window.open("https://maps.google.com/maps?daddr="+locationLatitude+","+locationLongitude+"&ll=");
}
</script>
I want to get the device rotation for (alpha, beta, gamma) for iPhone 7 and higher. For iPhone 6 this works well for me:
window.addEventListener('deviceorientation', function(event) {
console.log(event.alpha);
console.log(event.beta);
console.log(event.gamma);
});
But for iPhone > 6 this event is not triggered anymore. To be clear, i dont want the device orientation (portrait/landscape), I want the rotation. Best case would be absoulte (calibrated) data.
For Android "deviceorientationabsolute" works well. Is there something similar for the Apple universe?
Thanks & regards,
Andreas
for get device rotation in all devices better listen on resize window:
window.addEventListener('resize', function(){
if(window.innerWidth < window.innerHeight){
//portrait
}
if(window.innerWidth > window.innerHeight){
//landscape
}
});
Ok, the solution for me was to get the user permission to use orientation like this. After that 'ondeviceorientation' works.
function startOrientation() {
if (typeof DeviceMotionEvent.requestPermission === 'function') {
DeviceOrientationEvent.requestPermission().then(function(response) {
if (response == 'granted') {
console.log('granted');
}
});
} else {
console.log('not granted');
}
}
$("#get_permission").click(function(){
startOrientation();
});
I have been trying to detect touch screen in windows 8.1 specially on IE 10/11 as per my project requirement...
I have tried with Modernizer.touch but its getting false on IE (touch screen).
You can use navigator ?
function is_touch_device() {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}
if (is_touch_device()) {
alert("Yay! Its touch");
}else{
alert("Not touch!")
}
Full source:http://ctrlq.org/code/19616-detect-touch-screen-javascript
I can detect all handheld devices at the moment but can't separate tablet and mobile detection. I've searched lots of sources and q&a's but coudn't find a solution.
Since $.browser method removed from jQuery 1.9.1. We have to do it with native js.
Here is testing jsFiddle.
javascript:
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isTabletMobile = true : isTabletMobile = false;
//this works perfect
//problem starts when i try to detect difference between mobile and tablet
/iPad/i.test(navigator.userAgent) ? isTablet = true : isTablet = false;
//can't detect other tablet devices
/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? isMobile = true : isMobile = false;
//can't exclude tablet devices from here (like Android tablet devices)
if ( isTabletMobile ) {
alert('You are on Mobile or Tablet');
}else{
alert('You are on Destop device');
}
if ( isTablet ) {
alert('You are on Tablet');
}
if ( isMobile ) {
alert('You are on Mobile');
}
Source
you should check the screen sizes.
try some research for most minimum size of tablets.
then if the size of device you were checking is greater than or equal
to the minimum size for tablets, that means the device is a tablet.
var isDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? true : false;
var tabletMinWidth,
tabletMinHeight;
if(isDevice){
if(tabletMinWidth <= deviceWidth && tabletMinHeight <= deviceHeigth){
isTablet = true
}
}