Use the @ cc_on statement in Jscript to identify IE browser and version code _ javascript tips-js tutorial

Source: Internet
Author: User
Use the @ cc_on statement in Jscript to identify the IE browser and version code. For more information, see. Activation condition compilation is supported.
@ Cc_on remarks
@ Cc_on statement activates Conditional compilation in the script engine.
We strongly recommend that you use the @ cc_on statement in comments so that browsers that do not support conditional compilation will accept your script as a valid Syntax:
/* @ Cc_on */
// The remainder of the script. Or, an @ if or @ set statement outside The annotation will also enable Conditional compilation.
Requirements
Version 3
See
Reference
@ If... @ elif... @ else... @ end statement
@ Set statement

The Code is as follows:


/* @ Cc_on
@ If (@ _ jscript_version> 5.7)
Document. write ("You are using IE8 + ");
@ Elif (@ _ jscript_version = 5.7 & window. XMLHttpRequest)
Document. write ("You are using IE7 ");
@ Elif (@ _ jscript_version = 5.6 | (@ _ jscript_version = 5.7 &&! Window. XMLHttpRequest ))
Document. write ("You are using IE6 ");
@ Elif (@ _ jscript_version = 5.5)
Document. write ("You are using IE5.5 ");
@ Else
Document. write ("You are using IE5 or older ");
@ End
@*/


Concept
Conditional compilation Variables
Other resources
Conditional compilation
@ Cc_on condition compilation of IE

1: alert ("browser version:" + sSuffix)

It is useful to determine the browser version.
Var B =/* @ cc_on! @ */False;/* @ cc_on .....@*/
Can be recognized by ie and executed as a program, and ie Conditional compilation is enabled at the same time. The most common variable is @ _ jscript_version: js version. The last one is the main ie version.
Example:

The Code is as follows:


Var sSuffix = (/* @ cc_on! @ */False )? 'Ie': 'gecko ';
/* @ Cc_on alert ("display browser version:" + @ _ jscript_version )@*/
Alert (@ _ jscript_version)
Alert ("browser version:" + sSuffix)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.