JavaScript – Why Do We Need Different JS for Different Browsers?

javascript

What exactly are different things we need to take care when writing different JS files, like arrays, variables etc., Is there a book or website explaining differences between different JS engines used for browsers?

I was working on something in our application and bumped into a JS issue and was looking for solution and found out that we might need 2 different JS for different browsers to get my exact functionality. Why is that? Is that the browsers use different JS engines so they understand my JS in different ways?

Best Answer

I think your problem is not that there are different javascript engines (although there are). The problem that you are describing (that you need different code to get the same functionality) is probably because of various browsers understanding of HTML and particularly their implementation of the DOM. The work around HTML5 hopefully address a number of the areas of concern (although not all). This is taken directly from the HTML5 draft spec

1.5 Design notes

This section is non-normative.

It must be admitted that many aspects of HTML appear at first glance to be nonsensical and inconsistent.

HTML, its supporting DOM APIs, as well as many of its supporting technologies, have been developed over a period of several decades by a wide array of people with different priorities who, in many cases, did not know of each other's existence.

Features have thus arisen from many sources, and have not always been designed in especially consistent ways. Furthermore, because of the unique characteristics of the Web, implementation bugs have often become de-facto, and now de-jure, standards, as content is often unintentionally written in ways that rely on them before they can be fixed.

I think that expresses the problem quite nicely.

Related Topic