admin管理员组

文章数量:1401122

On one of our sites we get a very cryptic JS error from the Internet Explorer. In the console it says:

':' expected
javascript:false, Line 1 Character 24

When I click on the error to see which JS is causing the error a message pops up: "For this error no source is available". So I really can't tell you where this es from.

This is extremely cryptic to me. Does anyone know what could cause this?

On one of our sites we get a very cryptic JS error from the Internet Explorer. In the console it says:

':' expected
javascript:false, Line 1 Character 24

When I click on the error to see which JS is causing the error a message pops up: "For this error no source is available". So I really can't tell you where this es from.

This is extremely cryptic to me. Does anyone know what could cause this?

Share Improve this question asked Jan 24, 2012 at 16:55 Florian RachorFlorian Rachor 1,57415 silver badges31 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

That's probably from an incorrect object literal. For example:

var foo = {bar};

... gives exactly the error you describe in IE 7 and 8.

At a guess, a malformed object literal. Something like { foo bar } which should be { foo: bar }.

The places it would expect a colon are:

  1. Object literal e.g. var obj = {foo: bar};
  2. Ternary operator e.g. var str = (i === 0 ? "yes" : "no");
  3. Switch case statement

That could help you narrow it down. However, I suspect since you seem to indicate that the problem is only in IE that it is due to automatic semicolon insertion. For that I would run the scripts through JSLint to help find and correct ambiguities.

I can only really think of one place a colon is used in Javascript, and that's ternary operators. (Edit: Yes, there are object literals too, thanks other posters)

So is it possible you have a line that looks like it should be a Ternary op, but is missing the colon? This hypothesis is somewhat backed up by the talk in the error message of "false" as the part after the colon represents the false action.

Kind of got the same error with this jsfiddle: http://jsfiddle/CNTY8/

Expected ':'

本文标签: Cryptic javascript error in Internet Explorer 78 3939 expectedStack Overflow