Archive for July, 2007

45Chapter 13 .JavaScript Essentials set to display HTML (Web hosting reseller)

Tuesday, July 31st, 2007

45Chapter 13 .JavaScript Essentials set to display HTML that lets users know JavaScript is turned off, and therefore the full benefit of the page isn t available unless they turn on JavaScript. Listing 13-1 shows a skeletal HTML page that uses these tags. Listing 13-1: Employing the


The body of your document.

You can display any standard HTML within the

Top ten web hosting - 41Chapter 13 .JavaScript Essentials Nonscriptable browsers do not

Monday, July 30th, 2007

41Chapter 13 .JavaScript Essentials Nonscriptable browsers do not know about the tag. Therefore, their natural inclination is to render any lines they encounter after the opening JavaScript interpreters also know to ignore a line that begins with the HTML beginning comment sequence, but the interpreter needs a little help with the ending sequence. The close of the HTML comment starts with a JavaScript comment sequence (//). This tells JavaScript to ignore the line; but a nonscriptable browser sees the ending HTML symbols and begins rendering the page with the next HTML tag or other text in the document. An older browser doesn t know what the tag is, so the tag is ignored and rendering begins after that. Even with this subterfuge, not all browsers handle HTML comment tags gracefully. Some older America Online browsers display the script statements no matter what you do. Fortunately, these browsers are disappearing. If you design your pages for public access, include these HTML comment lines in all your Statements inside the tag set execute only upon the firing of the event. No function definitions are required. This way of binding an object s event to a script means that there is no event handler defined in the element s tag. Therefore, it guarantees that only IE4 or later can carry out the script when the event occurs. But the tag and attributes contain a lot of source code overhead for each object s script, so this is not a technique that you should use for script statements that need to be called by multiple objects. Also be aware that you cannot use this tag variation if non-IE or pre-IE4 browsers load the page. In such browsers, script statements execute as the page loads, which certainly causes script errors. JavaScript versus JScript and VBScript As previously explained, Internet Explorer s version of JavaScript is called JScript. As a result, Internet Explorer s default script language is JScript. While Internet Explorer acknowledges the LANGUAGE= JavaScript attribute, Netscape Navigator ignores the LANGUAGE= JScript attribute. Therefore, if you write scripts that must work in all scriptable browsers, you can specify one language ( JavaScript ) and count on all browsers interpreting the code correctly (assuming you take into account other browser compatibility issues). An entirely different issue is Internet Explorer s other scripting language, VBScript. This language, a derivative of Visual Basic, works only in Win32 versions of IE. You can mix scripts from both languages in the same document, but their tag sets must be separate with the LANGUAGEattributes clearly specifying the language for each tag set that specifies the scripting language via the LANGUAGEattribute. You can have any number of such tag sets in your document. For example, you can define some functions in the Head section to be called by event handlers in HTML tags within the Body section. Another tag set can reside within the Body to write part of the content of the page as the page loads. Place only script statements and comments between the start and end tags of the tag set. Do not place any HTML tags inside unless they are part of a string parameter to a document.write() statement that creates content for the page. Every opening How you use these later-version attributes depends on the content of the scripts and your intended audience. For example, while Navigator 6 is JavaScript 1.5-compatible, it works with all previous versions of the JavaScript LANGUAGEattribute as well. Features of the language that are new in JavaScript 1.5 are executed if the LANGUAGE attribute is set to only JavaScript . On rare occasions (detailed where necessary in Part IV), the behavior of the language changes in a browser if you specify a later language version (usually to force the script to adhere to the ECMA specification when it varies from earlier implementations). Writing scripts for a variety of browser versions requires a bit of care, especially when the scripts may contain language features available only in newer browsers. As demonstrated in an extensive discussion about browser detection later in this chapter, there may be a need to include multiple versions of a script function, each in its own