Home >Web Front-end >JS Tutorial >js method to determine whether the client is an iOS or Android mobile terminal_javascript skills

js method to determine whether the client is an iOS or Android mobile terminal_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:09:451292browse
Judgement principle:

JavaScript is the main language for front-end development. We can judge the type and version of the browser by writing JavaScript programs. There are generally two methods for JavaScript to determine the browser type. One is based on the unique attributes of various browsers, and the other is determined by analyzing the userAgent attribute of the browser. In many cases, after the browser type is determined by value, the browser version needs to be determined to handle compatibility issues, and the browser version can generally only be known by analyzing the browser's userAgent.

Browser type

⑴Browser-specific attributes
⑵According to userAgent
Browser version
⑴According to userAgent

For mobile browser judgment

1. How to judge whether it is a mobile terminal using regular match,
match whether navigator.userAgent contains the string AppleWebKit*****Mobile
The Android qq browser HD version only has AppleWebKit

2 Determining the mobile phone language version
Use navigator.browserLanguage to get the windows phone language version,
Of course the damn little mobile phone language version is also compatible The difference, browsers compatible with Mozilla, and Apple WebKit kernels access their language versions, it will list navigator.language
CODE:
Copy code The code is as follows:



Something special
UC Browser does not have an Android header , only returns: linux, here it is roughly judged to be Android based on linux (the prerequisite must be a mobile terminal, UC is satisfied)
The detection result of Android QQ Browser HD version is: mac, Safari
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn