go**********@yahoo.com (Artist) wrote in message news:<de**************************@posting.google. com>...
Mozilla and IE works different with Javascript.
I have Javascript Code which works fine with Mozilla
and it breaks with Internet Explorer.
I like to convert my code to work with both the browser.
What are the standard tools for the same?
Is there something which is mozilla specific that I should avoid to
have it working with internet explorer?
Thanks.!
First of all, there should be no need to convert your code. If you are
doing alot of complex DOM stuff, you may need to do some simple
browser detection and flip object and property references depending on
the browser. You should always use Moz as the base and if it does not
work in IE, then use an alternate code for IE in those cases.
For the most part, IE does support most open (mozilla) standards. Here
are a couple of areas that it does differ significantly.
Objects:
Although IE adds any HTML Element with an ID property to the
namespace to the 'all' property of 'document' object (which is a
default global reference after window I believe), the use of this
should be avoided at all costs. Instead always use
document.getElementById. Its the standard and will still work in IE.
The reverse is not true.
Event listeners:
In IE you cannot use ~Object~.addEventListener. You must directly
assign with either an inline assignment or ~object~.~eventname~ =
function handler(){... or equivalent. When you use the
~object.~eventname~ methodology, Mozilla by default assigns the event
object as an argument. IE does not. You will need to access the method
through window.event (or just event since window is the default global
namespace)
Arrays:
Mozilla is a little more flexible. With the array:
`["one","two","three",]`, Moz will ignore the last element and will
return an array of len 3. IE will return an array of Len 4 with the
last element as undefined. This can cause issues where you have server
code that iteratively generates JS arrays for you.
Form Elements:
Although its a good idea to use
window.forms["formname"]["elementname"] since it works in both
browsers, IE has a bug where if the first character is a number it
does not recognize the element. Generally I avoid using numbers as the
first character in elements because of this bug.
Regarding Tools, I just use a text editor and set up IE to dump any
errors to the screen (tools>internet options>advanced>display a
notification about every script error). I avoid using any script
debuggers. Just good debuging code that can build stack traces will
suffice. If you overload window.error, you can read the exact stack
trace in IE by jumping up the call stack through
arguments.callee.caller(.caller...)
Thats all I can think of off the top of my head. If you are having any
specific issues, please post the details.
Tim