Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do js, css and html judge different versions of browsers?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you js, css, html how to judge the various versions of the browser, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!

Using regular expressions to determine the version of ie browser

Determine whether or not an IE browser

If (document.all) {alert ("this is ie browser");}

Determine whether or not an IE6 browser

Method 1: if (/ MSIE 6.0/ig.test (navigator.appVersion)) {alert ("this is an ie6 browser");}

Or / MSIE 8/.test (navigator.appVersion)

Method 2:

Var IE =! +'\ v1'

IE6 = IE & & ([/ MSIE (\ d)\ .0 / i.exec (navigator.userAgent)] [0] [1] = = 6)

Determine whether or not an IE7 browser

If (/ MSIE 7.0/ig.test (navigator.appVersion)) {alert ("this is an ie7 browser");}

Judge IE browsers based on the above, other IE browsers in the same way, and so on.

Judge each browser by the browser version information

Var _ uat=navigator.userAgent

If (_ uat.indexOf ("MSIE 6.0") > 0) alert (" ie6 ")

Else if (_ uat.indexOf ("MSIE 7.0") > 0) alert ("ie7")

Else if (_ uat.indexOf ("MSIE 8.0") > 0) alert ("ie8")

Else if (_ uat.indexOf ("Firefox") > 0) alert ("firefox")

CSS determines the browser

# example {color:red;} / * firefox*/

* html # example {color:blue;} / * ie6*/

* + html # example {color:green;} / * ie7*/

HTML determines the browser

1. Can be recognized except IE

two。

3.

4.

5.

6.

7.

8.

Version number in css and js links in HTML

Background

Search for keywords in the search engine. Htaccess cache, you can search for many tutorials on setting up the caching of files on your website. By setting up, you can cache css, js and other infrequently updated files on the browser side, so that every time visitors visit your website, the browser can get css, js, etc., from the browser's cache without having to read them from your server. This accelerates the opening speed of the website to a certain extent, and can save your server traffic.

problem

Now the problem is that the css and js caches set by .htaccess have an expiration time. If css and js are already cached in the visitor's browser, before these css and js caches expire, the browser will only read css and js from the cache. If you modify css and js on the server, these changes will not change in the repeat customer's browser. Unless repeat customers press Ctrl + F5 to refresh your website page or manually empty the browser's cache. There are thousands of visitors to a website, and there will be a lot of repeat visitors. You can't ask every visitor to refresh the cache after updating css, so how do you deal with this problem?

Treatment method

1. Change the css file name: in fact, solving this problem is very simple, the cache marks the cached content through the file name. After you have updated the contents of the css file on the website, just change the file name of css. As in the original html, the css call statement is as follows:

Just change the name of the css file:

Another way to change the css file name from is to write the version number to the file name, such as:

After the css file is updated, you can change the version number in the file name:

two。 Add a version number to the css file: in fact, it is a bit troublesome to change the file name of the css every time you modify the css file, so we can add a version number in the load css statement (that is, in the css link? The rest) will be fine. As in the original html, the css call statement is as follows:

Just change the version number of the css file to 2012:

The above is all the contents of this article entitled "how js, css and html judge the various versions of browsers". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 280

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report