views:

54

answers:

2

I get an error on this line in IE8 with the Not Implemented error. How do i execute this line on other browsers and have IE8 ignore this?

window.onbeforeunload = function () {

This is weird. Theres nothing inside of this that should cause an error. This script is loaded at the end of body so all html exist and moving this code to the bottom on the file solved it. why?

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;
}
A: 

Use conditional comments, which means put a

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

arround your < script>-block

<!--[if !(IE 8)]>
<script type="text/javascript">
window.onbeforeunload = function () {
  [...]
}
</script>
<![endif]-->
JochenJung
This code is in a JS file rather then html. So i should split it and put a conditional around the include?
acidzombie24
Yes, then you could split it into two JS files and load the second one just if its not IE 8 with the conditional comments like explained above. But it will slow you page down a little, since your browser needs to load 2 JS files.
JochenJung
A: 

You might be able to use Conditional Compilation, the JS equivalent of Conditional Comments.

Not sure that you can do a browser sniff though.

Eric