John said:
Why not if different browsers behave differently using the same html, css &
js? I hope you know that IE does not conform to standards as good as a
browser like Firefox. IE is even buggy in many instances. Creating the same
js/css/html that works exactly the same way in all browsers is almost
impossible.
Granted, different browsers sometimes require JS that is different in
some details. But I have always been able to create JS that uses object
detection or (less often) browser detection in a single script to deal
with the differences.
For example, to get an object by id, I use this subroutine:
function getObject ( id )
{
if ( id == "" )
return( null );
if ( document.getElementById && (obj = document.getElementById(id)) )
;
else if ( document.all && (obj = document.all[id]) )
;
else /* DOM not supported, or no object */
return( null );
return( obj );
}
which either returns the object, if it exists, or null, if it does not
exist. This subroutine uses object detection to deal with the browser
differences: e.g., better browsers would use document.getElementById,
but IE5 (which does not support getElementById) would use document.all.
In either case the code calling this subroutine does not care which
browser it is, except that it should check for null to avoid error
messages of the sort you have seen.