We have a old Web Based application supported on browsers from IE6 to IE8 and javascript and css is very specific to the IE. Now we want to support IE9. In our javascript there are many syntaxes that are not supported in IE9, like accessing HTML attributes on element instances using dot (.) rather than setAttribute and getAttribute.
I was just wondering what is best way forward to support more browsers versions or support different browsers.
I was thinking like using jQuery to access non-standard features for all browsers or write a class called browser has method like getAttribute and then different class like IE7 and IE9 override this method on load in their specific way.
I want to use best way forward and approach used by users in such a scenrio.
setAttribute and GetAttribute are just simple examples there are many more for example to access the element reference we use document.all.elementName which is not supported in earlier versions of firefox etc. So how to convert all this code to Jquery or another library.
there are more problems then set and get attribute, the focus of question is what is best way to convert old javascript to supported javascript across all the browsers
Thanks
If you have a large amount of code written specifically for IE < 9 that you wish to work in other browsers, you first need to identify all the IE specific code and then replace it with cross-browser code. I don’t think any particular library will help with that, in fact POJS is likely easier.
For example, you can do a supervised replacement of
document.allwithdocument.getElementById, but you can’t do that with $ (where $ is from jQuery or Prototype or whatever).You’ll have issues using dot property access with non-standard attributes, but if they are set as properties, you’ll be fine (though it’s not a good idea to do so in principle).
Incidentally, jQuery doesn’t “override” get/setAttribute, it has its own
attrandpropmethods.Ultimately, you’ll likely end up rewriting the whole thing from scratch. Just remember, don’t target particular browser versions, support standards and address non-standard behaviour where necessary using feature detection and a good fallback strategy.