Jump to content

Coding For Old Browsers


CalBear

Recommended Posts

How important is to code for old browser compatibility? I have experimented with eliminating the following and found no problems with IE7+ (IE version 7 introduced in 2006), all versions of Firefox, Safari, and Chrome. 1) language = "javascript" 2) All the code relating to XMLHttpRequest just use Request = new XMLHttpRequest() for all browsers tested. 3) <!-- Start hiding JavaScript statements // End hiding JavaScript statements --> There may be some more sophisticated JavaScript code examples that do need some special browser compatibility coding. I would be interested to know what they are. However, it seems the three listed above could just be eliminated.

Link to comment
Share on other sites

1 and 3 are for even older browsers (Netscape...), so yeah. And 2... if you want to target IE6 as well, you might want to also use ActiveXObject.How important compatibility is depends on how much the browser is used by your target audience. If you're making a site for developers, you can assume IE8 at minimum and the latest versions of the other browsers. If you want to reach schools and (some) enterprises, you might want to also account for FF3 and IE7. If you want to reach every Windows XP user, you must support IE6 as well, since that's what comes with XP by default (IE8 is received through auto update, but not everyone turns it on, and some enterprises never upgrade).

Link to comment
Share on other sites

Thanks for the reply. Yes, I realize that XMLHttpRequest is a problem prior to IE7. I hadn't thought about the original installations of XP being IE6. My websites (non-profit organizations) do get occasional hits from IE6, generally much less than 1%. So I'll not worry about language and hiding but keep in mind the need to take care of XMLHttpRequest if I do a website where IE6 may be important.

Link to comment
Share on other sites

The things you have to check for nowadays are generally "features" that some browsers implement, but other (not necessarily older) ones don't. Some examples include events like copy and contextmenu, as well as new HTML5 stuff like localStorage. http://www.quirksmode.org/ is, as you may have gathered, a good place to find compatibility on the various JS features browsers may have implemented, and W3Schools also has a key on each page of its JS reference.

Link to comment
Share on other sites

If it wasn't clear from boen's answer, you should use the type attribute instead of the language attribute on script elements, and it's not necessary to use comments to hide Javascript or CSS. I'm not aware of a single browser that shows up on market share reports that doesn't understand Javascript or CSS.

Link to comment
Share on other sites

...it's not necessary to use comments to hide Javascript or CSS. I'm not aware of a single browser that shows up on market share reports that doesn't understand Javascript or CSS.
Though, if you have embedded script elements, the W3C HTML validator will complain about the JavaScript. So instead of using the HTML comment tags, you can use CDATA tags to "hide" the JavaScript from the validator.
<script type='text/javascript'>//<![CDATA[...code...//]]></script>

Link to comment
Share on other sites

I've never had validation problems with embedded JavaScript. Example... this validates (sorry about the formatting, it lost something in the cut/paste) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><title>Knock Knock Joke</title></head><body><script type="text/javascript">//Begin the first jokeresponse = window.prompt("Knock Knock!", "Who is there?");//Analyze the player's inputif (response == "Who is there?") { //Validate player inputresponse = window.prompt("Orange.", "Orange who?");if (response == "Orange who?") { //Validate player inputwindow.alert("Banana.");}}//Begin the second jokeresponse = window.prompt("Knock Knock!", "Who is there?");//Analyze the player's inputif (response == "Who is there?") { //Validate player inputresponse = window.prompt("Orange.", "Orange who?");if (response == "Orange who?") { //Validate player inputwindow.alert("Banana.");}}//Begin the third jokeresponse = window.prompt("Knock Knock!", "Who is there?");//Analyze the player's inputif (response == "Who is there?") { //Validate player inputresponse = window.prompt("Orange.", "Orange who?");if (response == "Orange who?") { //Validate player inputwindow.alert("Orange you glad I did not say banana?");}}</script></body></html>

Link to comment
Share on other sites

Validators and other parsers shouldn't mess up on the Javascript code, since the HTML DTDs specify the element as CDATA (i.e., containing character-data only):

<!ENTITY % Script "CDATA" -- script expression -->

<!ELEMENT SCRIPT - - %Script; -- script statements -->

Link to comment
Share on other sites

You'll get an idea of the browser support on browserscope. In a trice i would mark following:console functions won't work in IE ( <= 8, I assume).event.preventDefault won't work in IE ( <= 8). Workaround for this: event.returnValue = false; Oh, there are so much other funny differences ... :-)

Link to comment
Share on other sites

Validators and other parsers shouldn't mess up on the Javascript code, since the HTML DTDs specify the element as CDATA (i.e., containing character-data only):
<!ENTITY % Script "CDATA" -- script expression -->

<!ELEMENT SCRIPT - - %Script; -- script statements -->

Perhaps they've updated the validator now. It's been a while since I've actually used it on a page with JavaScript. I used to get errors when I had '<' symbols in the JavaScript. For example,
if (x < y) {

EDIT: Nope, they haven't updated it yet:post-33550-0-44976300-1320937211_thumb.jpg

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...