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 JavaScript with your page.

JavaScript has changed somewhat over the years and there are a few new commands that some older browsers still in use do not understand. What this means is that your JavaScript may function differently in different browsers. The only real way to check this is to actually test your script in those different browsers in order to see what works and what doesn't in the different browsers and in different versions of the same browser (particularly with Internet Explorer where older versions are still in use and each version has significant changes in what it supports compared to the prior version).

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 at least the latest two or three version of Internet Explorer, as well as the latest versions of Firefox, Google Chrome, Safari, and Opera. 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 having alternate content in the page which the JavaScript hides if the script is supported so that those browsers (such as Lynx) that don't support JavaScript or where your visitor has turned off Javascript support in their browser have an alternative way to achieve the same result by submitting their request for processing on the server instead..

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 Find on this page link and other menu options that require JavaScript will not be displayed. This provides some additional functions for those with JavaScript but is still quite useable for those without. 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. In fact the entire dexpanding menu uses CSS that really old browsers do not understand and anyone using one of those browsers will need to click on the menu in order to display a separate page listing all the navigation options.

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. Many years ago I was investigating a NewsScroller script that I found on one of the sites that offers Javascript 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 this was back when many of the CSS commands didn't work properly and so sites (including this one) used tables for layout. By doing this 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 JavaScript, 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 JavaScript that you will use on your site in (at least) those browsers I suggested above, you maximize the user friendliness of your script for all of the visitors who will be coming to your site. I haven't tested scripts written by other people for a number of years as more recently I have written my own versions of just about every script I can think of and have tested all of them across all the browsers I mentioned so that I know that I have working scripts for anything I want to be able to do.

I would suggest that the only time that it is not necessary to test your script in at least these 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 ayou control the browser then you only need to include code that works with that browser.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow