当前位置:网站首页>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.

边栏推荐
- One side is volume, the other side is layoff. There are a lot of layoffs in byte commercialization department. What do you think of this wave?
- AcWing 1126. Minimum cost solution (shortest path Dijkstra)
- 451 implementation of memcpy, memmove and memset
- AcWing 1127. Sweet butter solution (shortest path SPFA)
- RPD product: super power squad nanny strategy
- 励志!大凉山小伙全奖直博!论文致谢看哭网友
- AcWing 1128. Messenger solution (shortest path Floyd)
- AcWing 1129. Heat wave solution (shortest path SPFA)
- 从20s优化到500ms,我用了这三招
- For (Auto A: b) and for (Auto & A: b) usage
猜你喜欢
随机推荐
Embedded (PLD) series, epf10k50rc240-3n programmable logic device
台湾SSS鑫创SSS1700替代Cmedia CM6533 24bit 96KHZ USB音频编解码芯片
R language uses econcharts package to create microeconomic or macroeconomic maps, and indifference function to visualize indifference curve
From 20s to 500ms, I used these three methods
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
pytorch 模型保存的完整例子+pytorch 模型保存只保存可训练参数吗?是(+解决方案)
Sometimes only one line of statements are queried, and the execution is slow
NMF-matlab
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
After writing 100000 lines of code, I sent a long article roast rust
Postman interface test practice, these five questions you must know
After 65 days of closure and control of the epidemic, my home office experience sharing | community essay solicitation
JASMINER X4 1U深度拆解,揭开高效省电背后的秘密
开始练习书法
How to set priorities in C language? Elaborate on C language priorities
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
[internship] solve the problem of too long request parameters
KT148A语音芯片使用说明、硬件、以及协议、以及常见问题,和参考代码
c语言链表--待补充
In the era of consumer Internet, a few head platforms have been born








![[internship] solve the problem of too long request parameters](/img/42/413cf867f0cb34eeaf999f654bf02f.png)