R D*_*abh 1 javascript internet-explorer-8 jquery-mobile
我有一个js文件,并且只有在浏览器是IE 8时才想运行一些代码.有没有办法可以做到这一点?
现在我只有这个,但它适用于所有浏览器:
if ($.browser.msie) {
//do stuff for IE 8
}
Run Code Online (Sandbox Code Playgroud)
在JavaScript中查看浏览器检测? 和http://modernizr.com
这是简短的(est?)答案:
if (navigator.userAgent.match(/MSIE 8/) !== null) {
// do something in IE8
}
Run Code Online (Sandbox Code Playgroud)
特定于浏览器的代码几乎不是一个好主意.但是,如果必须这样做,则可以将代码放在条件注释中.
http://www.positioniseverything.net/articles/cc-plus.html
<!--[if IE 8]>
<script type="text/javascript">
// this is only executed for IE 8
</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18007 次 |
| 最近记录: |