Newer Version Available
HTML Comments and IE Conditional Comments
Visualforce removes most HTML and
XML comments from the page before rendering, without processing their contents. Internet
Explorer conditional comments, however, won’t be removed, allowing you to include
IE-specific resources and meta tags.
Internet Explorer conditional comments are most commonly used to address browser compatibility issues, generally with older versions of IE. Although conditional comments work wherever they’re used on the page, they’re frequently placed inside the page’s <head> tags, where they can be used to include version-specific stylesheets or JavaScript compatibility “shims.”
To place conditional comments inside a page’s <head> tag,
disable the standard Salesforce
header, sidebar, and stylesheets, and add your own <head> and <body>
tags:
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page docType="html-5.0" showHeader="false" standardStylesheets="false">
18 <head>
19 <!-- Base styles -->
20 <apex:stylesheet value="{!URLFOR($Resource.BrowserCompatibility, 'css/style.css')}"/>
21
22 <!--[if lt IE 7]>
23 <script type="text/javascript"
24 src="{!URLFOR($Resource.BrowserCompatibility, 'js/obsolete-ie-shim.js')}>
25 </script>
26 <link rel="stylesheet" type="text/css"
27 href="{!URLFOR($Resource.BrowserCompatibility, 'css/ie-old-styles.css')}" />
28 <![endif]-->
29
30 <!--[if IE 7]>
31 <link rel="stylesheet" type="text/css"
32 href="{!URLFOR($Resource.BrowserCompatibility, 'css/ie7-styles.css')}" />
33 <![endif]-->
34 </head>
35
36 <body>
37 <h1>Browser Compatibility</h1>
38 <p>It's not just a job. It's an adventure.</p>
39 </body>
40</apex:page>
Visualforce doesn’t support or
evaluate Visualforce tags, for
example, <apex:includeScript/>, within
standard HTML comments. However, it will evaluate the following expressions within IE
conditional comments:
- Global variables, such as $Resource and $User
- The URLFOR() function
See Microsoft’s documentation for Internet Explorer conditional comments for further details of how to use them.