针对IE 8及以下版本? [英] Targeting IE 8 and Below?
问题描述
我有一个在IE 9+和所有其他浏览器中运行良好的脚本。但在IE 8或更低版本中存在视觉错误。我可以通过更改IE 8及更低版本的一些动画效果来修复此视觉错误。要做到这一点,我需要在我的页面上有两个脚本。一个用于IE 9 +,Firefox,Chrome,Safari,另一个用于IE 8及更低版本。
I have a script that runs great in IE 9+ and all other browsers. But in IE 8 or below there are visual errors. I can fix this visual errors by changing some animation effects for IE 8 and below. To do this I need to have two scripts on my page. One for IE 9+, Firefox, Chrome, Safari, and the other for IE 8 and below.
以下是我的尝试:
// First the Script that runs for non-IE browsers.
<!--[if !IE]>
<script type="text/javascript">
// Script that runs
</script>
<![endif]-->
// Now for the Script for IE 8
<!--[if lt IE 9]>
<script type="text/javascript">
// Script that runs
</script>
<![endif]-->
第一个问题,主要的一个是在尝试时它似乎不起作用。 IE开始表现得很疯狂,脚本根本不起作用。如果我删除第一个脚本并离开第二个脚本它没有问题。似乎<! - [if!IE]><! - >
无法正常工作。
First Question and the main one is when attempting this it doesn't seem to work. IE starts acting crazy and the script doesn't function proerply at all. If I remove the first script and leave the second one it works without issue. It would seem that the <!--[if !IE]><!-->
is not working correctly.
第二个问题:使用<! - [if!IE]><! - >
我可以只针对IE 8及以下版本?
Second Question: Using <!--[if !IE]><!-->
can I target only IE 8 and below?
推荐答案
尝试 HTML5 Boilerplate 方式。然后在JS和CSS中按类定位IE版本。
Try doing it the HTML5 Boilerplate way. Then just target IE versions by class in JS and CSS.
用你的开头< html>
代替以下。根据您的需求调整:
Replace your opening <html>
tag with the following. Adjust to your needs:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
在JavaScript中:
In JavaScript:
var isIE8 = document.getElementsByClassName('lt-ie9').length;
var isIE7 = document.getElementsByClassName('lt-ie8').length;
if (isIE8) {
...
}
if (isIE7) {
...
}
这篇关于针对IE 8及以下版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!