This code (extracted from a javascript file) works in every major browser except IE (including IE8):
$('a[rel*=fancybox]').fancybox({ 'frameWidth' : 500, 'frameHeight' : 465, 'hideOnContentClick' : false, 'centerOnScroll' : true, }); |
This is the fix:
$('a[rel*=fancybox]').fancybox({ 'frameWidth' : 500, 'frameHeight' : 465, 'hideOnContentClick' : false, 'centerOnScroll' : true }); |
See the difference? Yeah, neither did I. The difference is the last comma in the argument list.
That’s 3 consecutive major versions of IE that have been absolutely crap. Why anyone continues to use IE is beyond me. IE: sucking hard since version 5.
It’s understandable. If you don’t know what is inside your computer, if you do not know the difference between “internet” and “WWW” or “browser” and “internet”, then you use Internet Explorer. In all other cases, you download a better browser. But those other cases are rare; the vast masses do not know much about computers; they just want to read their mail.
It’s not so much IE sucking hard, as it is JavaScript syntax sucking hard. No other language would expect a comma at the end of a list of arguments.
It appears that Internet Explorer is behaving correctly: according to ECMAScript grammar, the last item should not have a comma following it. Any browser in which this code works is accepting invalid syntax.
From ECMA-262, 11.1.5:
ObjectLiteral :
{}
{ PropertyNameAndValueList }
PropertyNameAndValueList :
PropertyName : AssignmentExpression
PropertyNameAndValueList , PropertyName : AssignmentExpression
@David, browsers operate in quirks mode 99% of the time, unfortunately. All major browsers understood this. IE broke ALL the js because of that. It should know better.
Adam,
As much as I detest being on the same side as MicroSoft, the trailing comma is, in fact, a syntax error which should be caught. While it might be an inadvertent interpretation of comma as terminator rather than separator, it might just as easily be interpreted as a missing list element.
Tracking down syntactically correct semantic errors is difficult enough; letting syntax errors slip through (without at least a warning message) makes tracking them down even more difficult.
James
I agree with the trailing comma, since it is the correct behaviour according to ECMAscript. But stopping interpreting your code, and breaking everything else – is definitely not the correct behaviour. It should work fine, but a warning is probably in place, though.
Yeah, agreed, the trailing comma is syntactically incorrect, I wouldn't expect that code to work without at least throwing an error; incomplete data set is incomplete.
However, it stands as testament to the other browsers that they can handle that error without keeling over, and it's not like having a null value in an array is something that should cause your entire browser to explode.