Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is JavaScript inconsistent across browsers?

Here's something I've been pondering after countless hours fixing JS to be cross-browser compatible (mostly IE): Why isn't Javascript consistent accross browsers?

I mean, why can't JS be nice like Java and Flash? Instead, we have to resort to frameworks like jQuery. Don't get me wrong, they make my life easier - but why do they even exist in the first place?

Is there a historical reason for this? Do companies rolling out browsers just ship their own JS engine? What are the politics that make standardization so difficult?

(Note: I understand that a good part of the problem is DOM related, but the question remains).

like image 537
NullUserException Avatar asked Aug 06 '10 19:08

NullUserException


People also ask

Does JavaScript work the same on every browser?

The Anatomy of the JavaScript engine. EcmaScript specification tells how JavaScript should be implemented by the browser so that a JavaScript program runs exactly the same in all the browsers, but it does not tell how JavaScript should run inside these browsers. It is up to the browser vendor to decide.

Is JavaScript inconsistent?

Unfortunately, JavaScript is also a dysfunctional programming language, imbued with a myriad of “warts” and “gotchas.” It lacks the discipline to be a serious software engineering language, thanks to loose typing and freewheeling coercions, and their wildly inconsistent semantics.

Why is JavaScript browser compatibility an issue in the first place?

Primarily errors in JavaScript browser compatibility pop up when website developers try to use modern JavaScript features that are not supported on older browsers or browser versions.


1 Answers

The Javascript core language for the most part is consistent ( Referring to ECMAScript version 3 released in 1999. )

It's the DOM implementations that cause headaches. Partly because at one point there was no DOM specification so browsers could do whatever the hell they wanted in terms of making up the rules for which to access and manipulate html elements in a web page.

For example:

  • window.addEventListener for DOM supporting browsers, while window.attachEvent for IE.
  • textContent for DOM supporting browsers, innerText for IE.
  • Memory leakage for attached event handlers in IE so you have to unload them manually
  • getElementById is buggy in IE and Opera because it returns elements by name
  • getAttribute('href') returns inconsistent values

There are also issues relating to the browser's CSS support.

  • IE6 doesn't support native PNGs so you are forced to use the filter library
  • Buggy animation in IE dealing with filter opacity

Language core inconsistencies would be things like

  • Inconsistencies between regex engines

But yeah, in short the point is that before, there was no standard. Since then, the w3 came up with standards, but every browser vendor has its own way of dealing with implementing it. There's no governing body that forces the vendors to fully apply the spec.

like image 179
meder omuraliev Avatar answered Oct 23 '22 00:10

meder omuraliev