Javascript vs. IE8 - Expected identifier, string or number

21,231

Solution 1

Try putting all your object properties in (double)quotes, like this:

$("div#slider").easySlider({
    'auto': false,
    'continuous': true,
    'nextId': "nextBtn",
    'prevId': "prevBtn"
});

Solution 2

In 2015. if you still care about IE8 compatibility (more or less), my issue with this error was only manifesting on a live server, but didn't happen on localhost (go figure). And, it triggered IE8 error in such a way that it went down into IE7 Compatibility View, which also sucks just the same as Quirks Mode.

In any case, the problem could not be solved by any of the above tips, and the issue was a trailing comma after listing some parameters/options.

For Example:

$(document).ready(function(){
    $('#selector').func({
        rules: {
            parameter1: {
                option1: true,
                option2: 1,
                option3: 5
            }
        }, // <- this trailing comma is fatal to IE8
    });
});

Solution 3

I had similar issue with knockout class attr binding. It happened that the class attribute had to be enclosed in quotes like 'class'.

Share:
21,231

Related videos on Youtube

jondavidjohn
Author by

jondavidjohn

Loving my wife, my sons, and my work. Building CodeShip by day and packtracker by night, otherwise you can probably find me outside 🧗🏻‍♂️🏕 http://jondavidjohn.com

Updated on July 09, 2022

Comments

  • jondavidjohn
    jondavidjohn almost 2 years

    No, it's not an extra comma.

    Here is the snip that is giving me the problem.

    $(document).ready(function(){   
        $("div#slider").easySlider({
            auto: false,
            continuous: true,
            nextId: "nextBtn",
            prevId: "prevBtn"
        });
    
        $("div#slider-banner").easySlider({
            auto: true,
            continuous: true,
            controlsShow: false
        });
            // <---------------------------------- Line 14
        $("div#slider-photos").easySlider({
            auto: true,
            continuous: true,
            controlsShow: false
        });
    
        $("#marquee").marquee({
            scrollSpeed: 25,
            pauseSpeed: 2000,
            showSpeed: 850
    
        }); 
    });
    

    ERROR DETAILS

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; Tablet PC 2.0; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
    Timestamp: Wed, 6 Apr 2011 15:20:42 UTC
    
    
    Message: Expected identifier, string or number
    Line: 14
    Char: 5
    Code: 0
    

    This is happening on random IE8 installs, any ideas?

    • Blender
      Blender about 13 years
      Did you beat it repeatedly and yell obscenities? That usually works when I debug IE. Now, back to business, have you tried removing those chunks of code? Knowing IE and it's clarity, it could be talking about line 14 of the plugin...
  • Mayo
    Mayo about 13 years
    That was my thought - char 5 coincides with the property identifiers. I don't think the syntax is wrong for object literals - but maybe one of those properties has a special meaning in a few of these IE8 installs? Or maybe there is a namespace issue that only shows up in IE8 (possibly only those with/without compatibility mode)?
  • Eric W.
    Eric W. over 10 years
    I had a similar issue with accessing an object's property via dot notation within a nested function. Switching to brackets solved the issue within IE8.
  • user56reinstatemonica8
    user56reinstatemonica8 about 10 years
    I think this might have something to do with property keys matching keywords? I had this problem with an object property named default and I only needed to put 'default' in quotes. I think here IE is freaking out at the object property name auto.
  • AsGoodAsItGets
    AsGoodAsItGets almost 7 years
    The OP started by explicitly stating "No, it's not an extra comma". This is the thing to check first in IE :)

Related