Testing
When you create web pages it is important that you make sure that all of the essential elements of the page appear in a useful way when viewed using different browsers and from different operating systems. The use of proprietary tags or tags not supported in earlier browsers can affect the appearance of your page.
This becomes even more important when you are going to use javascripts with your page. Different browsers support stylesheets and the Document Object Model to varying extents. In fact there are three different DOMs in use. There is the W3C standards one supported by IE6, Mozilla, Netscape 6+, Opera, etc. as well as proprietary DOMs used by Netscape 4 and IE4+. Also those browsers that do support the standard DOM do so to different extents with later versions of a browser supporting the DOM better than earlier versions of the same browser.
What this means is that even when you code your Javascript to use the standard DOM (or with code to support all three DOMs) that the Javascript may function differently in different browsers. The only real way to check this is to actually test your Javascript in different browsers in order to see what works and what doesn't in the different browsers and in different versions of the same browser.
This doesn't mean that you have to test your script and get it working in every possible browser, you'd never finish testing. What you do need to do is to test your script in all of the common browsers (and any not so common browsers that you particularly want to support). As earlier versions of a browser are less likely to function with a given script than later versions you may get away with testing with only one version of a particular browser. I would suggest that as a minimum scripts need to be tested with a version of Internet Explorer, Netscape 4, Netscape 6, and the earliest version of Opera that you want to support. You need to ensure that the script works on all of these browsers if the content of the script is important to the page. If it is not so important but is something you want to use where possible then the script needs to be coded so that for those browsers where it doesn't work that the code in the script is bypassed or an alternative code is executed that produces something equivalent that does work on those browsers. You may also want to consider <noscript> code for those browsers (such as Lynx) that don't support Javascript or where your visitor has turned off Javascript support in their browser.
As examples, some of the navigation on this web site is generated from Javascript. For those who don't have a browser that will run the Javascript, the site is still accessible via the site map link that appears on every page as well as via the topic pages. For those with Javascript support the exact list of links that appear depend on the browser that is being used. For those using IE or Netscape 4 (or 7), a Find on this page link shows in the navigation that will open a find script that works with those browsers but not with other browsers. Also with IE a Bookmark this Site link appears that uses a script that only works with IE. This means that the site can be navigated easier with those browsers that support the scripts that provide the additional functions but is still quite useable with the other browsers. I consider the extra navigation options provided by the Javascript to be "nice to have" add-ons for those who can use them but not essential for visitors to be able to use this site.
Sometimes the nature of the script requires that if you use it that you want it to work properly in as many browsers as possible. I recently was investigating a NewsScroller script that I found on one of the sites that offers Javascripts that you can freely copy and use on your site (provided that you include the original author's copyright statement). This newsscroller looked quite effective for highlighting important notices by scrolling the text up the screen. The documentation claimed that the script would work with IE, Netscape, and Opera but that there was a problem with getting it to scroll when used within a table with Mozilla. I decided to investigate the script further.
The first thing that I do when I get a script written by someone else is to test the supplied code on a number of different browsers just the same as I would if I had written the code. I usually do this because I am intending to rewrite the code to work the way that I want it to but I still suggest that you do the same because what is claimed and what is true are not necessarily the same thing as turned out to be the case in this instance. I deliberately inserted the code into a table because all of my pages use tables for layout so if I were to use the script then it would need to work in a table and secondly, I was hoping to be able to find and fix the problem that stopped the scroller from scrolling in Mozilla.
The results from my tests were surprising given the claims on the site where I got the script from. As expected, the script worked properly in Internet Explorer and didn't work in Mozilla. The surprising thing was that the script also didn't scroll in Opera 5 and Netscape 6. In Opera 6 the scroller scrolled part way then stopped and started from the top again meaning that only half the message was visible. Netscape 4 produced a blurred mess of text and background colour across the screen even though the script contained code specific to the Netscape DOM. Opera 7 was scrolling (I think) but everything on the page was vibrating sideways so rapidly that nothing was readable on the page.
So much for the usability of that script. I had tested on seven browsers and the code only worked on one even though the documentation claimed that it would work on most of the browsers that I tried. Perhaps it does work on most of those browsers when you don't include the script inside a table but that wasn't what I was looking for so I didn't test it that way.
This highlights the importance of testing Javascripts, not only those that you write yourself but those that you obtain from elsewhere. There is nothing worse than using a Javascript on your page that makes your page unusable in certain browsers. The browser in question may only be used by a small percentage of your potential visitors but you never know if they may turn out to be the visitors that you most want to have visit your site. By testing all of the Javascripts that you will use on your site in (at least) IE, Netscape 4, Netscape 6, and a version of Opera, you maximize the user friendliness of your script for all of the visitors who will be coming to your site.
I would suggest that the only time that it is not necessary to test your script in at least these four browsers is if you are writing for an intranet where you have control of the browsers that will be used to access the site. When you control the browser then you only need to include code that works with that browser.
What browsers do I test with? Well I have IE6, Netscape 4.7, Netscape 6.2, Mozilla 1.2, Opera 5, Opera 6, Opera 7, and Lynx on Windows NT that I use for most of my testing. I also have IE5.5, IE6, Netscape 7, and Opera 7.01 on Windows 98SE, Netscape 4.6, Mozilla 1.3, Opera 5, and Phoenix 0.5 on OS/2, and Netscape 4.7 on Linux that I can also use to test scripts across different operating systems if I think that is necessary.


