Sunday, April 17, 2011

Supporting all browsers

There was a time in the web's infancy where I would write javascript to determine which browser the end user was using. Doing so consisted of testing each browser and version. These days I use the jQuery $.support action. For example:

var someDocumentObject = document.getElementById('somePieceOfContent');
if($.support.leadingWhitespace)
{ someDocumentObject.style.leadingWhitespace= "top"; }
else
{ someDocumentObject.style.someStyleElement = "top"; }

If we check the property leadingWhitespace then we can check to see if it is supported by the user's browser. If not, we can use some style element that we know will work for browsers that don't support this property.

This won't fix all browser compatibility issues but it does help with a few of them.

No comments:

Post a Comment