-3

I'm not skilled enough to figure out what part of this is tripping up in IE9. I have a game that displays a word, and when they click on a div, it animates a flipping action and displays a description related to the word.

In IE9, it loads the first words but will not animate and show the description. This is the first thing I've ever created in jquery/javascript. It's a Frankenstein's monster of a couple of different jquery libraries and some javascript.

What do I have to look into in order to get this to work?

Here's the code:

        <script src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      // Load jQuery
      google.load("jquery", "1");   
    </script>
    <script src="js/jquery-ui-1.7.2.custom.min.js"></script>
    <script src="js/jquery.flip.min.js"></script>
    <script src="js/jquery.xml2json.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
    var cC = 0;
    var flashcards;
    var aCards = [];
    var totalCards = Number(0);
    var cardToggle = Boolean(false); //not Flipped to start out
    $.get('xml/den204_fc_module01.xml', function(xml) {
        var flash = $.xml2json(xml);
        flashcards = flash.card;
        for (var i = 0, len = flashcards.length; i < len; i++) {
            var tempCards = flashcards[i];
            aCards.push({
                t: tempCards.term,
                d: tempCards.def
            });

            function shuffle(array) { // from: http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript
                var counter = array.length, temp, index;
                while (counter > 0) {
                    index = (Math.random() * counter--) | 0;
                    temp = array[counter];
                    array[counter] = array[index];
                    array[index] = temp;
                }

                return array;
            }

            shuffle(aCards);
            totalCards = aCards.length;
            $('#containerFront').text(aCards[cC].t);
            $("#previousSet").addClass("disabled");
        }
    });
    $(document).ready(function() {
        $("#clickableCard").click(function() {
            if (cardToggle === false) {
                console.log('cardToggle is equal to false');
                cardToggle = true;
                $("#flipbox").flip({
                    direction: "tb",
                    color: "#ffd699",
                    content: "<div id='containerBack'>" + aCards[cC].d + "</div>",
                    speed: 400,
                });
            } else {
                console.log('cardToggle is equal to true');
                cardToggle = false;
                $("#flipbox").flip({
                    direction: "bt",
                    color: "#adc2d6",
                    content: "<div id='containerFront'>" + aCards[cC].t + "</div>",
                    speed: 400,
                });
            }
            return false;
        });
        $("#navi").click(function() {
            if (cardToggle === true) {
                console.log('cardToggle is equal to true');
                cardToggle = false;
                $("#flipbox").flip({
                    direction: "bt",
                    color: "#adc2d6",
                    content: "<div id='containerFront'>" + aCards[cC].t + "</div>",
                    speed: 200,
                });
            }
            if (cC === 0) {
                $("#previousSet").addClass("disabled");
            } else {
                $("#previousSet").removeClass("disabled");
            }
            if (cC == (totalCards - 1)) {
                $("#nextSet").addClass("disabled");
            } else {
                $("#nextSet").removeClass("disabled");
            }
        });
        $("#nextSet").click(function() {
            console.log(cC);
            if (cC < (totalCards - 1)) {
                ++cC;
                $('#containerFront').text(aCards[cC].t);
                $('#containerBack').text(aCards[cC].d);
            } else {
                console.log("cC is not less than or equal the total number of cards!");
            }
        });
        $("#previousSet").click(function() {
            console.log(cC);
            if (cC > 0) {
                --cC;
                $('#containerFront').text(aCards[cC].t);
                $('#containerBack').text(aCards[cC].d);
            } else {
                console.log("cC is not greater then 0!");
            }
        });
    });
    </script>
kking
  • 42
  • 6
  • 4
    Remove all `console.log` from your code. In `IE9` the `console` object is only alive when you're in debugging mode. – painotpi Jun 24 '13 at 16:26
  • 1
    please see http://meta.stackexchange.com/questions/125997/something-in-my-web-site-or-project-doesnt-work-can-i-just-paste-a-link-to-it – Liam Jun 24 '13 at 16:27
  • 1
    Why do you have `Number(0)` and `Boolean(false)`? Don’t try to make JavaScript look statically-typed, please. It doesn’t work. Also, `=== true` is usually redundant. `cardToggle === false` is better written `!cardToggle`. – Ry- Jun 24 '13 at 16:28
  • It's working for me just fine, with or ***WITHOUT*** console being open. what is the error? because i get new cards on every click same as in Chrome or FF – SpYk3HH Jun 24 '13 at 16:30
  • I'm new here and I fully admit it! I'm also new to javascript. Sorry for causing confusion with my title. – kking Jun 24 '13 at 16:32
  • @minitech can you point me at some websites that explain what you're talking about? I don't fully understand. If I don't use `Number(0)` and `Boolean(false)` what should I use? – kking Jun 24 '13 at 17:04
  • @kking: `0` and `false`. `0` is already a number and `false` is already a boolean. – Ry- Jun 24 '13 at 17:04

2 Answers2

2

Remove or comment out the console.log statements in your code. IE chokes on them unless the console is open.

To address SpYk3HH's comments below, this comes from one of Microsoft's own blogs:

Keep in mind you will not be able to see the output unless you have the developer tools open. You can see the console output on either the Console or Script tabs. Be careful when using console for debugging. If you leave a call to the console object in your code when you move to production and you do not have the developer tools displayed you will get an error message telling you console is undefined.

j08691
  • 204,283
  • 31
  • 260
  • 272
  • I've never seen IE choke on a console statement and I have proggies with console logging that some clients use in IE6! (of course the console logging is for when i debug in Chrome, but the point is as stands). – SpYk3HH Jun 24 '13 at 16:28
  • 1
    @SpYk3HH Did you read this answer fully? The last sentence says **unless the console is open**. – Ian Jun 24 '13 at 16:29
  • 1
    @SpYk3HH: Perhaps because you’ve had the console open. Read the whole answer. And the whole other answer too. – Ry- Jun 24 '13 at 16:29
  • Yes I did, and My IE 6 users don't even know what a console is, and it still works – SpYk3HH Jun 24 '13 at 16:30
  • @SpYk3HH: Do you use some sort of shiv that fixes it? – Ry- Jun 24 '13 at 16:31
  • 1
    @SpYk3HH Then you don't have `console` statements in your code, or you have some library/code that fills it so it doesn't fail. – Ian Jun 24 '13 at 16:32
  • nope, good old fashioned `console.log('message here')` and i've never seen a single app of mine crash any IE6+ – SpYk3HH Jun 24 '13 at 16:32
  • 3
    @SpYk3HH: It doesn’t crash the browser. The *script* just doesn’t work. `console` is `undefined`. This is kind of well-known. I’m just going to give you the benefit of parallel-universe doubt and boot up Windows, though. – Ry- Jun 24 '13 at 16:33
  • @minitech well then you should explain that to all the script i have that runs just fine, with console.log debugging info in it in IE. Guess my script is just special on the dozen different PC's and different programs I've used over the years to write stuff, but what do i know – SpYk3HH Jun 24 '13 at 16:34
  • Works in IE7, just tested, with console closed https://myclinicom.com/index.php/mobile/ccmaster/ – SpYk3HH Jun 24 '13 at 16:40
  • @SpYk3HH - no idea why you or your users use IE6, however using `console.log` in various versions of IE is a known issue. See my update. – j08691 Jun 24 '13 at 16:40
  • 1
    @SpYk3HH: Okay. Are you *actually* using IE7? Or are you in IE7 compatibility mode in IE10? – Ry- Jun 24 '13 at 16:41
  • 2
    commenting out the console.log did it. Thanks! – kking Jun 24 '13 at 16:42
  • 1
    @SpYk3HH - In IE8 your link gives the error: `Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E) Timestamp: Mon, 24 Jun 2013 16:43:44 UTC Message: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. Line: 3 Char: 3436 Code: 0 URI: https://myclinicom.com/js/jQuery/jQuery.js` – j08691 Jun 24 '13 at 16:44
1

Remove all console.log from your code.

In IE9 the console object is only alive when you're in debugging mode.

If you do want to log stuff, you can do this,

if(console || console !== undefined){
   //log here
}
painotpi
  • 6,894
  • 1
  • 37
  • 70
  • IE doesn't crash on console logging. If that were the case, I'd have been out of business years ago – SpYk3HH Jun 24 '13 at 16:32
  • 2
    @SpYk3HH It does. Stop making stuff up. `console` statements don't work unless the console is open in IE. If you have code that fills it so that it doesn't work, that's not the rest of the world's problem – Ian Jun 24 '13 at 16:32
  • I'm not saying it crashes :S – painotpi Jun 24 '13 at 16:33
  • @Ian you're the one making stuff up. I been doing this for years, check the resume. `console.log` **DOES NOT CRASH IE** – SpYk3HH Jun 24 '13 at 16:33
  • @SpYk3HH let me setup a fiddle for you – painotpi Jun 24 '13 at 16:33
  • 3
    @SpYk3HH It doesn't crash the browser, but script after it in the execution won't run. I really don't care what your resume says, we all have experience – Ian Jun 24 '13 at 16:34
  • 1
    @SpYk3HH Try opening this in IE: http://jsfiddle.net/A6xTk/show/ - do you get an `alert`? No. That's because the `console.log` statement right before it causes the execution to fail. Open up Developer Tools, refresh the page, and it works fine – Ian Jun 24 '13 at 16:37
  • @Ian Is this valid for IE10? – painotpi Jun 24 '13 at 16:38
  • @Ian roflmao, case and point: pull this up in IE with f12 off, then look at console on a reload https://myclinicom.com/index.php/mobile/ccmaster/ not much to see there, but you can see JS still working just fine if you click login button in top right – SpYk3HH Jun 24 '13 at 16:38
  • 1
    @SpYk3HH it will work in IE10 afaik, are you looking in ie9? – painotpi Jun 24 '13 at 16:39
  • 1
    @SpYk3HH: IE10 fixes the bug. You said it works in IE6, so try IE6. – Ry- Jun 24 '13 at 16:39
  • @badZoke I don't know, I'm not sure if it keeps the console "open" in the background like other browsers. And I'm not sure how it works in compatibility mode – Ian Jun 24 '13 at 16:39
  • And yes, I just opened that page in IE7, looked funky, but all JS still worked – SpYk3HH Jun 24 '13 at 16:39
  • 2
    @SpYk3HH LIES ! if you're switching modes, make sure it's the proper standard as well. – painotpi Jun 24 '13 at 16:40
  • 1
    @SpYk3HH I don't know why you need to post a full website. As I've already provided, the fiddle I made doesn't work in old IE as you won't see an alert – Ian Jun 24 '13 at 16:42
  • 1
    @SpYk3HH And the website you posted doesn't even work or show up in IE8 **with** Developer Tools open. And it warns me about insecure content. What a joke – Ian Jun 24 '13 at 16:44
  • @SpYk3HH: Compare http://netrenderer.com/index.php?url=http://ietest.comlu.com/ie-console.html&browser=ie9 and http://netrenderer.com/index.php?url=http://ietest.comlu.com/ie-console.html&browser=ie10 – Ry- Jun 24 '13 at 17:01