我只想在java脚本的Internet Explorer中使用警告框...如何写入.js文件。
<!--[if IE 8]><!-->
alert("only in IE8");
<!--<![endif]-->
我之前使用过这段代码,但它不起作用..是否需要添加js文件来执行此代码或任何代码。
if (isIE8) {
alert('Your browser is IE8');
}
如果我使用此代码,javascript将停止执行chrome和firefox。
答案 0 :(得分:0)
针对此问题的一个好方法是为IE8呈现具有不同类名的html
标记。
像这样。
<!doctype html>
<!--[if IE 8 ]><html class="ie8"><![endif]-->
<!--[if !IE]><!--><html><!--<![endif]-->
<head>
<script type="text/javascript">
//with jQuery
(function(){
if($('html').is('.ie8')) {
alert('This is IE8');
}
});
//with JavaScript
function ElementHasClass(elem, class) {
return (' ' + elem.className + ' ').indexOf(' ' + class + ' ') > -1;
}
var htmlElement = document.getElementsByTagName("html")[0];
if (ElementHasClass(htmlElement, "ie8")){
alert('This is IE8');
}
</script>
</head>
<body>
</body>
如果您需要特殊风格
,您还可以在CSS中使用课程ie8
答案 1 :(得分:0)
感谢您的回复..我为该警报使用了另一个代码..
if(navigator.appVersion.indexOf("MSIE 8.")!=-1)
{
alert("File Deleted Successfully");
}
这是针对IE8的。它的工作原理
答案 2 :(得分:0)
我得到了警报的答案,请根据需要尝试使其完美运行。
<!--[if IE 8]> <html class="lt-ie9"> <![endif]-->
<script type="text/javascript">
if(IE10orBelow() < 9) {
alert('Update Your ie explorer or use other brower!');
}
function IE10orBelow() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
}
</script>