当前位置:网站首页>How to realize the function of detecting browser type in Web System
How to realize the function of detecting browser type in Web System
2022-07-02 19:59:00 【Promise__ shallow】
origin
Sometimes we need to restrict the type of browser when users access the system , So that users can get a better experience , For example, the system you developed is chrome The most perfect compatibility under , You may not want users to use other browsers to access your system . For example, the following effect
So how is this effect done ?
Realize the idea
When the user first enters the page , Detect the user's browser , Judge if it's not the browser you need , The corresponding interface is displayed , Otherwise, it can be used normally .
Key code - page
<div class="dbw-internet-tips">
<div class="dbw-tips-title"><img src="assets/img/nodata.png" alt=""></div>
<div class="dbw-tips-con"> In order to give you a better experience , Please use <span class="dbw-tips-chrome"> Google browser </span> see </div>
<div class="dbw-tips-download"> Google browser is not installed ?<span class="dbw-btn-download"> Click to download </span></div>
</div>
- 1.
- 2.
- 3.
- 4.
- 5.
Key code -JS
$(function () {
// Judge whether it is chome, If not, prompt to use chrome Or download chrome
ischrome();
// Determine whether the browser is edge browser , If yes, the prompt
getBrowser();
}
// Judge whether it is chome, If not, prompt to use chrome Or download chrome
function ischrome() {
var isChrome = navigator.userAgent.toLowerCase();
if (!isChrome.match(/chrome/)) {
nochrome();
} else {
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");
function _mime(option, value) {
var mimeTypes = navigator.mimeTypes;
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
return false;
}
// Judge whether you are 360 browser
if(is360){
nochrome();
}
// Is it Edge browser
/* else if(navigator.userAgent.indexOf("Microsoft Edge")) {
nochrome();
}*/
else{
yeschrome();
}
}
}
// Determine whether the browser is edge browser , If yes, the prompt
function getBrowser(getVersion) {
var ua_str = navigator.userAgent.toLowerCase(), ie_Tridents, trident, match_str, ie_aer_rv, browser_chi_Type;
if("ActiveXObject" in self){
ie_aer_rv= (match_str = ua_str.match(/msie ([\d.]+)/)) ?match_str[1] :
(match_str = ua_str.match(/rv:([\d.]+)/)) ?match_str[1] : 0;
ie_Tridents = {"trident/7.0": 11, "trident/6.0": 10, "trident/5.0": 9, "trident/4.0": 8};
trident = (match_str = ua_str.match(/(trident\/[\d.]+|edge\/[\d.]+)/)) ?match_str[1] : undefined;
browser_chi_Type = (ie_Tridents[trident] || ie_aer_rv) > 0 ? "ie" : undefined;
}else{
browser_chi_Type = (match_str = ua_str.match(/edge\/([\d.]+)/)) ? "edge" :
(match_str = ua_str.match(/firefox\/([\d.]+)/)) ? "firefox" :
(match_str = ua_str.match(/chrome\/([\d.]+)/)) ? "chrome" :
(match_str = ua_str.match(/opera.([\d.]+)/)) ? "opera" :
(match_str = ua_str.match(/version\/([\d.]+).*safari/)) ? "safari" : undefined;
}
var verNum, verStr;
verNum = trident && ie_Tridents[trident] ? ie_Tridents[trident] : match_str[1];
verStr = (getVersion != undefined) ? browser_chi_Type+"/"+verNum : browser_chi_Type;
console.log(verStr);
if(verStr == 'edge') {
nochrome();
}
}
// Show browser version prompt
function nochrome() {
var bodys = $('body');
bodys.find('.dbw-login-container').remove();
bodys.css('background','none');
$('.dbw-internet-tips').show();
$('.dbw-btn-download').click(function() {
location.href='root/googlechromexp_49.0.2623.112.exe';
});
}
// Hide browser version tips
function yeschrome() {
$('.dbw-internet-tips').hide();
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
About download function
There is a downloaded code on the door , We just need to place the files to be downloaded in the corresponding directory
location.href='root/googlechromexp_49.0.2623.112.exe';
- 1.
边栏推荐
- Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
- checklistbox控件用法总结
- 【实习】解决请求参数过长问题
- 测试人员如何做不漏测?这7点就够了
- JASMINER X4 1U deep disassembly reveals the secret behind high efficiency and power saving
- 【Hot100】22. bracket-generating
- 蓝牙芯片ble是什么,以及该如何选型,后续技术发展的路径是什么
- VBScript详解(一)
- Burp install license key not recognized
- Attack and defense world PWN question: Echo
猜你喜欢
SBT tutorial
自动生成VGG图像注释文件
Istio1.12:安装和快速入门
KT148A语音芯片ic的开发常见问题以及描述
八年测开经验,面试28K公司后,吐血整理出高频面试题和答案
Istio部署:快速上手微服务,
Why do I have a passion for process?
Kt148a voice chip instructions, hardware, protocols, common problems, and reference codes
Taiwan SSS Xinchuang sss1700 replaces cmmedia cm6533 24bit 96KHz USB audio codec chip
Attack and defense world PWN question: Echo
随机推荐
How can testers do without missing tests? Seven o'clock is enough
Overview of browser caching mechanism
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
Kt148a voice chip IC user end self replacement voice method, upper computer
数据库模式笔记 --- 如何在开发中选择合适的数据库+关系型数据库是谁发明的?
Jetson XAVIER NX上ResUnet-TensorRT8.2速度与显存记录表(后续不断补充)
API documentation tool knife4j usage details
CRM客户关系管理系统
After writing 100000 lines of code, I sent a long article roast rust
upload-labs
接口测试到底怎么做?看完这篇文章就能清晰明了
For (Auto A: b) and for (Auto & A: b) usage
自动生成VGG图像注释文件
[internship] solve the problem of too long request parameters
How my mother-in-law and daughter-in-law get along
[NLP] a detailed generative text Abstract classic paper pointer generator
Postman下载安装
B-end e-commerce - reverse order process
From 20s to 500ms, I used these three methods
esp32c3 crash分析