View Single Post
Old 01-17-2008, 12:35 PM   #7 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

...And Javascript is client-side and so can be a bit of a pain like cross-compatibility in HTML. One of the functions that really sticks out with its bad cross-compatibility is the add function for select fields, but thankfully Javascript has support for try and catch blocks and so it's really quite simple:

javascript Code:
pSelect = document.getElementById('mySelect');
pOption = document.createElement('option');

pOption.innerHTML = 'This is my option';

try
{
    pSelect.add(pOption, null);
}
catch(pEx)
{
    pSelect.add(pOption);
}

You have to do that because Internet Explorer doesn't support the second argument, whereas all other browsers requires you at least to set it to null.

With the increasing popularity of Javascript frameworks such as Prototype and jQuery, browser incompatibilities, such as class and className, as well as CSS opacity in JS, are all relatively easy to overcome by using the functions from the frameworks which try their utmost to increase that compatibility. They do this by simply by wrapping our try and catch block above in a function of their own which we can then call without a try and catch block and have it work perfectly.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 3 Users Say Thank You to Wildhoney For This Useful Post:
conrad (01-19-2008), hello-world (02-15-2009), SOCK (01-18-2008)