conditional-commentsgoogle-chrome-frame

Is it possible to use conditional comments from within a Chrome Frame?


When using...

<!--[if lte IE 8]> <html class="ie8-7-6"> <![endif]-->
.ie8-7-6 .loginForm {display:none;} /* The login form is hidden. */

and

.ie8-7-6 .yourbrowserisold {display:block;} /* and some nice graphics 
appear to indicate it doesn't support IE6, 7, or 8. */

So that works very nicely and I'm providing a link to download Chrome Frame.

But now, if Chrome Frame is installed, I would like it to do the oposite.

<!--[if CF]><html class="chrome-frame><![endif]--> 
.chrome-frame .yourbrowserisold {display:none;}
.chrome-frame .loginForm {display:block;}

But

<!--[if CF]><html class="chrome-frame><![endif]--> 

does not work and I need the login form to appear.

I've googled a few dozen websites and I can't find an answer if...

a. it is even possible with conditionals?

b. or is it only possible with javascript?

Any help?

-----Update---------- Here is a script to detect if Google Frame is installed or not.

$(document).ready(function() {
     if( $.browser.chromeframe != window.externalHost) {alert("You are using chrome frame. You rock!"); } 
else { alert("You are not using chrome frame."); }
});

FYI: You can add your own jQuery to the above script to target Chrome Frame users.

----- Demo: https://dev.clientwhys.com/index-dummy-ie.iml


Solution

  • The best way to detect that you're in Chrome Frame inside IE is checking for

    var isChromeFrame = !!window.externalHost;
    

    This is only available inside Chrome Frame. Currently there are no conditional comments-like construct for Chrome Frame.

    More at http://www.chromium.org/developers/how-tos/chrome-frame-getting-started/understanding-chrome-frame-user-agent.

    But to your situation, if the user has Chrome Frame installed already and you're triggering it via a chrome=1 flag, then they'll never see any content inside of IE conditional comments.