简体   繁体   中英

Blocking certain devices and browsers from my website

从我的网站阻止旧版本的浏览器和移动设备的最佳方法是什么(阻止他们(向他们发送消息以了解该网站兼容的浏览器))?

The best way is to use feature detection to detect whether the features you require are supported by the browser. The library modernizr contains a wealth of feature detection logic that you can either use from the library or you can borrow individual elements from and copy into your code. The reason this is the best way is because you aren't stuck with tracking and keeping up with individual versions of individual browsers and you aren't relying on browser type and version identification which is not guaranteed to be accurate and can be explicitly set by users to spoof. With feature detection, either the host browser has a capability you need or it doesn't and this is figured out at run-time. If your site is not usable on small screens, you can use feature detection to test for window size.

Another way (but certainly not the best way) is to detect a browser type and version and inform the user if they are using a version you haven't tested. You can use the navigator.userAgent property and examine what's in that string to identify various browsers and browser versions. There's a whole library here that gives you an idea what you can look for.

If you're using jQuery, then you can use jQuery.browser and jQuery.browser.version as it has already parsed some of the information from the useragent string.

Anything can be "spoofed" but you could use jquery.browser to do this. Find more info here: jQuery

A few conditional if else if statements could provide an error message that their browser is not compatible. Again this would not be 100% fool proof, but if you are trying to block users that are still using really old browsers, I would think it would be pretty effective.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM