未实施IE8:解决这个问题?

时间:2010-07-17 14:09:02

标签: javascript internet-explorer-8

我在IE8中使用Not Implemented错误在此行上出错。我如何在其他浏览器上执行此行并让IE8忽略它?

window.onbeforeunload = function () {

这很奇怪。没有任何内容可能导致错误。这个脚本在body的末尾加载,所以所有的html都存在,并将这个代码移到文件的底部解决了它。为什么呢?

window.onbeforeunload = function () {
    var txtbox = $('.box textarea').eq(0);
    var txt = txtbox.val();
    var btn = $('.box button').eq(0).html();
    if (btn == "Thank You")
        return;
    if (btn == "Sending")
        return "not complete";
    if (txt != '') {
        return "blah"
    }
    return;
}

2 个答案:

答案 0 :(得分:0)

使用条件评论,即放置

<!--[if !(IE 8)]>
<![endif]-->

围绕你的&lt;脚本&GT; - 嵌段

<!--[if !(IE 8)]>
<script type="text/javascript">
window.onbeforeunload = function () {
  [...]
}
</script>
<![endif]-->

答案 1 :(得分:0)

可能能够使用Conditional Compilation,相当于条件评论的JS。

不确定您是否可以通过浏览器嗅探。