You can use libraries such as jquery
to manage browser compatibility.
Checkout more details on this website: https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/JavaScript
Some snippet from aforementioned website:
Historically, JavaScript was plagued with cross-browser compatibility
problems — back in the 1990s, the main browser choices back then
(Internet Explorer and Netscape) had scripting implemented in
different language flavours (Netscape had JavaScript, IE had JScript
and also offered VBScript as an option), and while at least JavaScript
and JScript were compatible to some degree (both based on the
ECMAScript specification), things were often implemented in
conflicting, incompatible ways, causing developers many nightmares.
Such incompatibility problems persisted well into the early 2000s, as
old browsers were still being used and still needed supporting. This
is one of the main reasons why libraries like jQuery came into
existence — to abstract away differences in browser implementations
(e.g. see the code snippet in How to make an HTTP request) so
developers only have to write one simple bit of code (see
jQuery.ajax()). jQuery (or whatever library you are using) will then
handle the differences in the background, so you don't have to.