我正在尝试为 IE 8 或更低版本的用户更改 iFrame 的 SRC
属性。
这是我的代码:
<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>
它检测到它是 IE...但仍将所有 IE 用户发送到 shopping_cart/browser_support.html
。即使我使用 IE 9,它也会将我发送到那里。 7 或 8 也是如此。
但它会将所有其他不使用 IE 的用户发送到 shopping_cart/index.html
(这是正确的)。
我的代码有什么问题?
谢谢!
最佳答案
您不能在 script 标签内插入 。它需要在外面。
<script>
var i_am_old_ie = false;
</script>
<!--[if lte IE 8]>
<script>
i_am_old_ie = true;
</script>
<![endif]-->
关于javascript - IE 8 的条件注释不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11767108/