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

爱⌒轻易说出口 提交于 2019-12-02 09:22:17

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/11908896/is-it-possible-to-use-conditional-comments-from-within-a-chrome-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!