如果浏览器是IE 8或更低版本,请避免加载整个页面

时间:2014-08-14 01:41:17

标签: javascript html angularjs

我的网页有问题,此时我正在使用以下内容验证浏览器版本:

<!--[if lte IE 9]>
<div id="ie-compatibility">
   <h1>Your browser is out of date</h1>
</div>
<![endif]-->

但是有效但是整个页面都被加载了(js libs,样式表,其他div等等),当条件存在时,有一种方法不加载整个页面吗?我只是想显示一条消息和一些图像,而不是关于我的ie兼容性(作为附加数据,我在我的项目中使用AngularJS)。

谢谢你提前。

3 个答案:

答案 0 :(得分:0)

我不是Angular开发者,而是对IE版本进行快速JS检查(请参阅Best way to check for IE less than 9 in JavaScript without library)并采取相应措施。

如果你想在那里加载页面加载,document.execCommand('Stop');。否则,你可以简单地从你不想加载的dom中获取和删除元素,如果你设法在加载中尽早插入(当然取决于http请求的数量和大小,这可能不是超级高效。)

答案 1 :(得分:0)

在加载外部内容的任何元素之前插入它应该这样做。

<!--[if lte IE 9]>
    <script type="text/jscript">
        document.write(String.fromCharCode(60,33,45,45,32))
    </script>
<![endif]-->

您甚至可以在脚本标记之前添加h1警告。

请注意,您当前的状况(lte IE 9)包括IE 9 &amp;下面,不是8&amp;下面。您可能只需要lt IE 9

您还可以撤消逻辑并跳过旧版浏览器的标题:

<!--[if gte IE 9]-->
    … external style and script content …
<!--[endif]-->

答案 2 :(得分:-1)

如果您使用的是jQuery,您可以在该条件下编写一个脚本来删除默认的html并附加新的html:

<!--[if lte IE 9]>
<script>
    $('body').empty().append([*new html*])
</script>
<![endif]-->