JS to determine the mobile browser operating system and micro-browser methods
To do the front-end development of mobile phones, without the judgment of the mobile phone platform. For app downloads, for example, you should be judged to show Android downloads under the Android platform, and iOS downloads on the iOS platform.
Today I would like to introduce you to use JS to judge the mobile phone client platform and system platform method:
<script type= "Text/javascript" >//Mobile terminals to determine the platform browser and operating system platform function checkplatform () {if (/android/i.test (navigator.useragent)) {document.write ("this is Android ' browser. '); /This is the Android platform under browser} if (/(Iphone|ipad|ipod|ios)/i.test (navigator.useragent)) {document.write ("this is IOS ' browser. '); /This is the iOS platform under browser} if (/linux/i.test (navigator.useragent)) {document.write ("This is linux ' browser."); /This is the Linux platform under browser} if (/linux/i.test (Navigator.platform)) {document.write ("this is linux operating system. "); /This is the Linux operating system platform} if (/micromessenger/i.test (navigator.useragent)) {document.write ("this is Micromessenger ' browser. ");
/This is the micro-trust platform under the browser} $ (document). Ready (function () {alert (navigator.platform); Checkplatform ();}); </script>
PHP to determine the operating system mobile browser code
An Egg pain project, a very 龊 solution, with a perfect judgment, this is nothing, I speechless, alas. No nonsense, look at the theme, today and you share is that if you use PHP to determine the current browser's operating system (including mobile phones and ipad and other tablets) and browser name and version number. Because before I (Web Programming Technology Exchange Network) also wrote some articles "php identify user browser and the system used" "PHP to judge the browser type of code" "JS and PHP to judge the browser type of method" essence "" JS Judge browser type ", Today to do a summary of these documents and strengthen the function of the mobile phone operating system is also added to the judgment, something more comprehensive, of course, this thing, I can not save he is always correct, because the standards of each browser are not the same. So, if the wrong place or bug everyone can exchange, PHP judge Browser, support a variety of browsers at home and abroad, and the use of the platform. Be quite a force to ... is a PHP class. The
mainly involves the following methods (to do a simple description): 1.isBrowser ($browserName)//judgment is a browser, parameter write browser name 2.getBrowser ();//Get the name of the browser 3.getPlatform () ;//Get the type of operating system, such as Windows or Linux or ... 4.getVersion ()//Get the browser version number 5.getAolVersion ();//Get AOL 6.isAol ();//To determine whether it is AOL 7.isMobile (), or whether it is a mobile browser, with a browser, not a third party. 8.isRobot ();//Whether from the search engine 9.getUserAgent (); 10.isChromeFrame ()///...
The main implementation of several methods, including and the judge, operating system, such as the judgment.
Protected function checkbrowsers () { return (
$this->CHECKBROWSERWEBTV () | |
$this->checkbrowserinternetexplorer () | |
$this->checkbrowseropera () | |
$this->checkbrowsergaleon () | |
$this->checkbrowsernetscapenavigator9plus () | |
$this->checkbrowserfirefox () | |
$this->checkbrowserchrome () | |
$this->checkbrowseromniweb () | | // common mobile
$this->checkbrowserandroid () | | $this->checkbrowseripad () | |
$this->checkbrowseripod () | |
$this->checkbrowseriphone () | |
$this->checkbrowserblackberry () | |
$this->checkbrowsernokia () | | // common bots
$this->checkbrowsergooglebot () | |
$this->checkbrowsermsnbot () | |
$this->checkbrowserslurp () | | // WebKit base check (post mobile
and others) $this->checkbrowsersafari () | | // everyone else
$this->checkbrowsernetpositive () | |
$this->checkbrowserfirebird () | |
$this->checkbrowserkonqueror () | |
$this->checkbrowsericab () | |
$this->checkbrowserphoenix () | |
$this->checkbrowseramaya () | |
$this->checkbrowserlynx () | |
$this->checkbrowsershiretoko () | |
$this->checkbrowsericecat () | |
$this->checkbrowserw3cvalidator () | | $this->checkbrowsermozilla () /* mozilla is such an open
standard that you must check it last */ ); } protected function checkbrowseropera () { if ( stripos ($this->_ Agent, ' Opera mini ') !== false ) { $
Resultant = stristr ($this->_agent, ' Opera mini '); if ( preg_match ('/\//', $resultant) ) { $aresult = explode ('/', $resultant)
; $aversion = explode (' ')
, $aresult [1]);
$this->setversion ($aversion [0]); } else {
$aversion = explode (' ', stristr ($resultant, ' Opera mini '));
$this->setversion ($aversion [1]); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} $this->_
browser_name = self::browser_opera_mini;
$this->setmobile (true);
return true; &NBSP;&NBSP;&NBSP;&NBSP} else if ( stripos ($this->_agent, ' opera ') !== false ) { $resultant = stristr ($this-
>_agent, ' opera '); if ( preg_match ('/version\/(10.*) $/', $resultant, $matches)
) { $this->setversion ($matches [1]); } else if ( preg_match ('/\//', $resultant) ) { $aresult = explode ('/', Str_replace ("(", " ", $resultant));
$aversion = explode (' ', $aresult [1]);
$this->setversion ($aversion [0]);
} else { $aversion = explode (' ')
, Stristr ($resultant, ' Opera ')); $this->setversion (Isset ($averSION[1])? $aversion [1]: ""); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP} $this->_
browser_name = self::browser_opera;
return true;
} return false; }
Protected function checkplatform () { if ( stripos ($this->_agent, ' windows ' !== false ) { $this->_
Platform = self::P latform_windows; &NBSP;&NBSP;&NBSP;&NBSP} else if ( stripos ($this->_agent, ' IPad ') !== false ) { $this->_platform =
self::P Latform_ipad; &NBSP;&NBSP;&NBSP;&NBSP} else if ( stripos ($this->_agent, ' IPod ') !== false ) { $this->_platform =
self::P latform_ipod; &NBSP;&NBSP;&NBSP;&NBSP} else if ( stripos ($this->_agent, ' IPhone ') !== false ) { $this->_platform =
self::P latform_iphone; &nBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' mac ') !== false ) { $this->_platform = self:
:P latform_apple; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' Android ') ! == false ) { $this->_platform =
Self::P latform_android; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' Linux ') !== false ) { $this->_platform = self:
:P Latform_linux; &NBSP;&NBSP;&NBSP;&NBSP} else if ( stripos ($this->_agent, ' Nokia ') !== false ) { $this->_platform =
self::P Latform_nokia; } else if ( stripos ($this->_agent, ' BlackBerry ') !== false ) {
$this->_platform = self::P latform_blackberry; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' FreeBSD ') !== false ) { $this->_platform = self:
:P Latform_freebsd; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' OpenBSD ') !== false ) { $this->_platform = self:
:P Latform_openbsd; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' NetBSD ') !== false ) { $this->_platform = self:
:P Latform_netbsd; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' OpenSolaris ' !== false ) {
$this->_platform = self::P latform_opensolaris; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' SunOS ') !== false ) { $this->_platform = self:
:P Latform_sunos; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' OS\/2 ') !== false ) { $this->_platform = self:
:P Latform_os2; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' BeOS ') !== false ) { $this->_platform = self:
:P Latform_beos; &NBSP;&NBSP;&NBSP;&NBSP} elseif ( stripos ($this->_agent, ' win ') !== false ) { $this->_platform = self::
Platform_windows; &NBSP;&NBSP;&NBSP;&NBSP}}
The bright spot of this method is the ability to judge the browser of a mobile phone and browser and the operating system of a computer's mobile phone, and if you can combine these with the basics, you are invincible in this judgment. I hope I can help you.
PHP Determines whether the user's browser type is a micro-browser
This question has been discussed before this site, directly to see the past: http://www.111cn.net/phper/php/64226.htm