Question:
Is most JavaScript compatible with most browsers?
john
2010-05-31 21:15:46 UTC
What percentage of JavaScript do I need to worry about not being compatible?
Five answers:
richarduie
2010-06-01 06:30:44 UTC
I've never tried to calculate a percentage of compliance or variability of JavaScript across browsers and never seen anyone report it that way. I'm not certain how one would compute such a value meaningfully. However, there are major differences in the implementations of JavaScript between IE and just about everybody else. Most non-IE browsers, e.g., Firefox, Chrome, Opera, Safari, etc., are VERY similar to each other JavaScript-wise. In almost every case that I have branch code for handling things differently in JavaScript, depending on the browser, my comments to detail the branches are simply "IE" and "non-IE" (everybody else).



If you can lay hands on a copy of O'Reilly's "JavaScript: The Definitive Guide" ( http://oreilly.com/catalog/9780596101992/ ), it offers the best presentation of the differences in all aspects across browsers. Base language aspects of syntax are consistent. The prototype OO basis of the language is reliably implemented in the same (apparent) fashion. That's the end of the good news.



Microsoft follows an ENTIRELY different event model than that used in most other browsers. For an online discussion of differences between the event model of IE and that of the more compliant, non-IE browsers, see:



http://www.javascriptkit.com/jsref/event.shtml



The structure of the DOM differs in some pretty extreme ways in IE vs. the rest of the world. Since the DOM differs between IE and others, there are also JavaScript differences related to function and property names. That is, for DOM elements that differ, the properties differ, and hence, the functions by which to access the different elements also vary.



If you're willing to accept the weight (lots of code + steep learning curve) of some of the JavaScript libraries such as the YUI, JQuery, etc., many of the differences are concealed beneath an abstraction layer. This allows you to remain ignorant of the differences, since you call the library functions that "always" work the same in all browsers. Frankly, I prefer knowing the differences, since the libraries are pretty huge - including JavaScript frameworks for trivial purposes is not a bandwidth burden I want to inflict on my visitors or customers. There's also the potential for conflicts between multiple libraries. I've seen huge numbers of question in Y!A and elsewhere along the lines, "I had everthing working with JS_library_X until I needed to add JS_library_Y - now everything's broken...HEEEELP!" Coders who only know the libraries rarely understand how to identify and resolve such errors.



To summarize, there are MANY differences, some huge, others small and insidiously sneaky.
J.J.'s Advice / Avis de J.J.
2010-06-01 04:35:40 UTC
JavaScript is understood and parsed by all mainstream browsers. The issue isn't with whether the language is compatible or not, just if your application of the language is compatible. Some browsers will account for small errors in your script and others won't. Some browsers will accept issues with standards compliance as long gas the code is technically still correct, whereas others will only accept fully compliant code.

To be safe, write your code adhering precisely to the standards. If you find then that it doesn't work in all browsers, you can do some tweaking.
doug
2010-06-01 04:42:12 UTC
Different browsers have different script engines that interpret and run javascript (ECMAscript). These various engines attempt different implementations of the same standard, ECMAscript.



http://en.wikipedia.org/wiki/List_of_ECMAScript_engines



Try to stick with the standard as close as you can, but realize that the standard, although mostly implemented, is rarely fully implemented in all browsers. (This is true with the DOM as well: http://en.wikipedia.org/wiki/Document_Object_Model)



Avoid proprietary junk, if possible.



One of the better sites around, IMO, for javascript compatibility issues is:



http://www.quirksmode.org/



good luck.
Ratchetr
2010-06-01 04:22:53 UTC
Most JavaScript is compatible with most browsers most of the time.



Biggest issues I have run into is minor syntax errors that work on one browser and fail on others. And event handling isn't 100% consistent.



Best advice is to test early and test often against all major browsers. And when a browser reports an error....don't assume it's just a crappy browser because the code works right on a good one. The good one may just be more forgiving of crappy code ;-)
Not me. Or is it...
2010-06-01 04:17:34 UTC
Do you mean different versions of Javascript? Most mainstream browsers (Firefox, IE, Chrome, Opera, Safari) can handle Javascript.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...