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 to determine the browser version of the statement and be compatible with multiple browsers

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article focuses on "how to judge the browser version of the sentence and can be compatible with multiple browsers", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to judge the browser version of the statement and is compatible with multiple browsers"!

IE6 and its following versions are visible

IE7 and its following versions are visible

Only the IE6 version is visible

Versions other than IE

IE8 and its following versions are visible

IE7 and its following versions are visible

Usage:

(1)

You can use the following code to detect the version of the current IE browser (note: you can't see the effect in non-IE browsers)

You are using an IE browser

Version 5

Version 5.0

Version 5.5

Version 6

Version 7

What if the current browser is IE, but the version is lower than IE5? you can use it. Of course, conditional comments can only be in the IE5+ environment, so they will not be executed at all. Lte: it's short for Less than or equal to, which means less than or equal to. Lt: it's the abbreviation of Less than, which means less than. Gte: it's short for Greater than or equal to, which means greater than or equal to. Gt: it is the abbreviation of Greater than, which means greater than. !: it means that it is not equal to, and it is the same as the unequal judgment character in javascript.

(2)

How to apply conditional comments is explained at the beginning of this article, because different versions of IE browsers have different interpretations of our WEB standard pages, specifically, the interpretation of CSS is different. in order to be compatible with these, we can use conditional comments to define respectively, and finally achieve the goal of compatibility. For example:

< !–- 默认先调用css.css样式表 –->

< !-–[if IE 7]>

< ![endif]–->

< ![endif]–>

This distinguishes the execution of CSS by IE7 and IE6 downward browsers to achieve compatibility. At the same time, the default css.css on the first line is compatible with other non-IE browsers.

Note: the default CSS style should be on the first line of the HTML document, and all content determined by conditional comments must be after the default style. For example, the following code appears red in IE browsers and black in non-IE browsers. If you put the conditional comment judgment on the first line, it cannot be implemented. This example is a good illustration of how to solve the compatibility problem between IE browsers and non-IE browsers. Body {background-color: # 000;}

< /style>

< !-–[if IE]>

Body {background-color: # F00;}

< /style>

< ![endif]–->

At the same time, some people will try to define the situation in non-IE browsers, but note that conditional comments can only be executed in IE browsers. Under non-IE browsing, this code not only executes the definition under that condition, but is ignored as comments.

Normal is the default style, and conditional comments are made only if IE browsers need special treatment. In HTML files, not in CSS files.

These comments are now available in DWcs4: in "window-> code snippet-- > comment". The other versions didn't pay much attention to it.

At this point, I believe you have a deeper understanding of "how to judge the browser version of the statement and can be compatible with multiple browsers". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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: 0

*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