概述
关于获取语言(通用)
使用 window.navigator.language 即可获取语言
使用 window.navigator 可以获取当前的浏览器的信息
{
“vendorSub”: “”,
“productSub”: “20030107”,
“vendor”: “Google Inc.”,
“maxTouchPoints”: 0,
“hardwareConcurrency”: 4,
“cookieEnabled”: true,
“appCodeName”: “Mozilla”,
“appName”: “Netscape”,
“appVersion”: “5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36”,
“platform”: “Win32”,
“product”: “Gecko”,
“userAgent”: “Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36”,
“language”: “zh-CN”,
“languages”: [
“zh-CN”,
“zh”
],
“onLine”: true,
“doNotTrack”: null,
“geolocation”: {},
“mediaDevices”: {},
“plugins”: {
“0”: {
“0”: {}
},
“1”: {
“0”: {},
“1”: {}
},
“2”: {
“0”: {}
},
“3”: {
“0”: {},
“1”: {}
},
“4”: {
“0”: {}
}
},
“mimeTypes”: {
“0”: {},
“1”: {},
“2”: {},
“3”: {},
“4”: {},
“5”: {},
“6”: {}
},
“webkitTemporaryStorage”: {},
“webkitPersistentStorage”: {},
“serviceWorker”: {},
“budget”: {},
“permissions”: {},
“presentation”: {}
}
扩展,使用该属性可以获取浏览器的版本号,浏览器名称,具体代码如下:
<!DOCTYPE html>
<html>
<head>
<title>JS获取当前使用的浏览器名字以及版本号</title>
<meta charset="utf-8">
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var userAgent=window.navigator.userAgent,
rMsie=/(msies|trident.*rv:)([w.]+)/,
rFirefox=/(firefox)/([w.]+)/,
rOpera=/(opera).+version/([w.]+)/,
rChrome=/(chrome)/([w.]+)/,
rSafari=/version/([w.]+).*(safari)/;
function uaMatch(ua)
{
var match=rMsie.exec(ua);
if(match != null)
{
return {browser:"IE",version:match[2] || "0"};
}
var match=rFirefox.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rOpera.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rChrome.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rSafari.exec(ua);
if(match != null)
{
return {browser:match[2] || "",version:match[1] || "0"};
}
if(match != null)
{
return {browser:"",version:"0"};
}
}
function init()
{
var browser="";
var version="";
var browserMatch=uaMatch(userAgent.toLowerCase());
if(browserMatch.browser)
{
browser=browserMatch.browser;
version=browserMatch.version;
}
alert(browser+"
"+version);
}
</script>
</head>
<body onload="init()">
</body>
</html>
最后
以上就是体贴斑马为你收集整理的工作中的知识点总结的全部内容,希望文章能够帮你解决工作中的知识点总结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复