IE 8的条件评论不起作用

lar*_*555 0 html javascript jquery

我正在尝试为SRCIE 8或更低版本的用户更改iFrame 的属性.

这是我的代码:

  <script>
var i_am_old_ie = false;
<!--[if lte IE 8]>
i_am_old_ie = true;
<![endif]-->
</script>
    <script type="text/javascript">
    $(document).ready(function() {
if(i_am_old_ie) {
   $("#shop").attr("src","shopping_cart/browser_support.html"); 
} else {
    $("#shop").attr("src","shopping_cart/index.html"); 
}      
});
</script>
Run Code Online (Sandbox Code Playgroud)

它检测到它是IE ...但仍然发送所有IE用户shopping_cart/browser_support.html.即使我使用IE 9,它也会将我发送给我.对于7或8也是如此.

但它发送所有其他不使用IE的用户shopping_cart/index.html(这是正确的).

我的代码有什么问题?

谢谢!

Pao*_*ndo 6

您无法在脚本标记内插入.它需要在外面.

<script>
var i_am_old_ie = false;
</script>

<!--[if lte IE 8]>

<script>
i_am_old_ie = true;
</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)