admin管理员组文章数量:1331849
I have a slider, it shows 4 videos, I need to show the picture when I go through with mobile device, video when through a desktop , the slider is written in main.min.js
, and includeed in the main.tpl
(template), and i have a script that detect mobile device
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
// Any tablet device.
if( $detect->isTablet() ){
what should i do to show the picture when I go through with mobile device, video when through a desktop?
I have a slider, it shows 4 videos, I need to show the picture when I go through with mobile device, video when through a desktop , the slider is written in main.min.js
, and includeed in the main.tpl
(template), and i have a script that detect mobile device
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
}
// Any tablet device.
if( $detect->isTablet() ){
what should i do to show the picture when I go through with mobile device, video when through a desktop?
Share Improve this question asked Apr 10, 2019 at 6:09 Arsen OspanovArsen Ospanov 131 gold badge1 silver badge12 bronze badges 4- did you tried this solution? stackoverflow./a/4117597/4459647 – MRustamzade Commented Apr 10, 2019 at 6:11
- 4 You should not use php to determine user device, since php is a server side language, it is not a good way to do that. you can easily use CSS and/or JS/jQuery to identify user device since they work on client side, – Vishwa Commented Apr 10, 2019 at 6:11
- @Vishwa What's wrong with detecting the device at the server-side? Knowing the device you can offer a customized version of your page for specific devices. – Teemu Commented Apr 10, 2019 at 6:14
- 1 @vishwa so which way do you suggest? and what should i write – Arsen Ospanov Commented Apr 10, 2019 at 6:19
2 Answers
Reset to default 3I think the best way is to check by user agent. WordPress has a wp_is_mobile fucntion in it's core that might help (I've removed WP parts of it):
function is_mobile() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
$is_mobile = false;
} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false // many mobile devices (all iPhone, iPad, etc.)
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mobi' ) !== false ) {
$is_mobile = true;
} else {
$is_mobile = false;
}
return $is_mobile;
}
For detecting if a mobile device is a tablet or a phone, I don't think user agent help much. here is a list of tablet user agents that I found: Tablet User Agents
Try this class http://mobiledetect, it's best for detecting different devices.
// Include and instantiate the class.
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
if ( $detect->isMobile() ) {
// Show the image here for mobile
}
if ( !$detect->isMobile() ) {
// Show the image here for puter
}
本文标签: javascriptDetect mobile device in PHPStack Overflow
版权声明:本文标题:javascript - Detect mobile device in PHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742222042a2435506.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论