Microsoft HTA/Version checking

From Computernewb Wiki
Revision as of 22:58, 17 May 2022 by Dartz (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
< Microsoft HTA/Using VBScript!


You've reached the final tutorial in the Microsoft HTA tutorial series. This tutorial is about using Internet Explorer conditional comments to check whether a specific version of IE is being used or not. Conditional comments are fairly simple. They start with <!--[if (expression)]> and end with <![endif]-->.

Making expressions

Expressions are used in conditional comments to restrict content to certain versions of Internet Explorer. Let's begin with a simple expression: if IE 6. This checks if the IE version is equal to 6. Maybe you want to check if a version of Internet Explorer is below or equal/above IE7. In that case, you can have two different conditional comments: if lt IE 7 and if gte IE 7. The lt and gte operators are two of the four numerical operators that can be used instead of the default equals operator. There is a table below showing the different numerical operators.

Numerical operators in conditional comments
Conditional comment operator Mathematical sign Description
(default) = Equal to
gt > Greater than
gte Greater than or equal to
lt < Lesser than
lte Lesser than or equal to

There are also three Boolean operators: And, Or, and Not. Before using the operators, surround the first operand (including their numerical operators) with parentheses and then put the symbol where it needs to go (before for Not and after for And/Or). In the case of two-operand operators (And/Or), place the second operand after their symbol. Make sure that the second operand has parentheses too!

Boolean operators in conditional comments
Conditional comment operator Name in Boolean logic Operands Description
& And 2 If both expressions are true
| Or 2 If either expression is true
! Not 1 If expression is false

Using conditional comments

Here is an example of the use of conditional comments:

Language: HTA
<!DOCTYPE html>

<html>
  <head>
    <title>Internet Explorer Style Test</title>
    <HTA:APPLICATION
      APPLICATIONNAME = "Internet Explorer Style Test"
    />
  </head>
  <body>
    <h1>Internet Explorer Style Test</h1>
  </body>
</html>