The Wayback Machine - https://web.archive.org/web/20081201144653/http://www.webreference.com/html/tutorial16/4.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 16 / 4

index12345678

Tutorial 16: Client-Side Scripting 101

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Specifying the scripting language

You should always specify both the MIME content type of the script and the language the script is in. Although the LANGUAGE attribute is deprecated, you should use it because older browsers do not recognize the TYPE attribute.

The proper value for the TYPE attribute is a bit of a thorny issue. The Internet Assigned Numbers Authority (IANA) has not assigned any media types for JavaScript (or any other of the popular scripting languages, for that matter). Normally, this would mean that you would use an experimental media type by prefixing the string x- to the type. Indeed, the media type most commonly used to describe JavaScript is application/x-javascript. There are two problems with this, however. First of all, the HTML 4.0 Specification recommends, as examples, that the content types text/javascript, text/vbscript and text/tcl be used for the JavaScript, VBScript and Tcl languages. This is obviously wrong, since none of these types have been registered with IANA. This would not really be a problem if it wasn't for a bug in Internet Explorer 4.0 and later versions. These browsers will only run scripts that have one of the following media types: text/javascript, text/jscript or text/ecmascript for JavaScript, and text/vbscript or text/vbs for VBScript. This does force us to use one of the above, and my preference amongst these would be text/ecmascript, as it covers all scripting languages that conform to ECMA-262 (which includes the latest versions of both JavaScript and JScript).

So, for example, if you want to insert a script that is located at http://www.acme.com/scripts/foo.js, you could use something like the following:

The values accepted by the LANGUAGE attribute are mostly browser-dependant. The purpose of both the LANGUAGE and TYPE attributes are to allow browsers that don't support a particular scripting language to ignore the particular script. So, for instance, if a browser doesn't grok the "FooScript" language, it would ignore the following script:

<SCRIPT
 TYPE="application/x-fooscript"
 LANGUAGE="FooScript"
 SRC="http://www.acme.com/scripts/bar.fs"
>
</SCRIPT>

Traditionally, most JavaScript-capable browsers also understand a version number appended to the language name in the LANGUAGE attribute, for instance, something like the following:

<SCRIPT
 TYPE="text/ecmascript"
 LANGUAGE="JavaScript1.2"
 SRC="http://www.acme.com/scripts/foo.js"
>
</SCRIPT>
<SCRIPT
 TYPE="text/jscript"
 LANGUAGE="JScript3.0"
 SRC="http://www.acme.com/scripts/bar.js"
>
</SCRIPT>

Presumably, a browser that understands JavaScript, version 1.2, will process the first script, and a browser that understands JScript (Microsoft's semi-compatible version of JavaScript), version 3.0, will process the second script.

In practice, this is a mess. Older browsers didn't even process the LANGUAGE attribute and just blindly executed all scripts as JavaScript, while various browser makers set up their browsers so that they run scripts with LANGUAGE attributes that are not really compatible. The reason is that browser makers are anxious to have their browsers run every script, regardless of whether they can, and are not willing to let someone as puny as an author decide that their script won't run in their browser.

Generally speaking, using the LANGUAGE attribute to decide whether or not a browser can run a script is a bit of a bad idea. The best solution I would recommend is to specify the language only (no version number) in the LANGUAGE attribute and the appropriate MIME content type in the TYPE attribute. If there is a question of compatibility between different versions of the scripting language, what you should do is test capabilities (not version numbers!) of the scripting language within your script. An excellent example of how to do this in JavaScript is given by Peter Belesis in WebReference.com's Dynamic HTML Lab, along with an explanation of why checking for a browser version number is a bad idea.

index12345678

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

URL: http://www.webreference.com/html/tutorial16/4.html

Produced by Stephanos Piperoglou
Created: September 15, 1999
Revised: September 27, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.