Skip to content

Instantly share code, notes, and snippets.

@oliver-moran
Created September 23, 2012 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliver-moran/3770452 to your computer and use it in GitHub Desktop.
Save oliver-moran/3770452 to your computer and use it in GitHub Desktop.
Stating the language used in scripts
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- We will set the default scripting language to VBScript. -->
<meta http-equiv="Content-Script-Type" content="text/vbscript" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Stating the language used in scripts</title>
</head>
<body>
<h1>Stating the language used in scripts</h1>
<p>Currently, JavaScript is the default scripting language for the web. In fact, only Internet Explorer implements another scripting language (VBScript) in addition to JavaScript. However, in theory, there could be more and in future a specific client may not support JavaScript as the default scripting language (or even at all!).</p>
<p>In HTML4, when using the <code>script</code> tag, the <code>type</code> attribute is mandatory. In HTML5, it is mandatory if the script is not JavaScript. The language to used in event attributes can be identified by preceding the script code with <code>javascript:</code>, <code>vbscript:</code>, etc..</p>
<p>Additionally, in HTML4, <a href="http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.2.1">authors should state</a> the default scripting language through HTTP headers or a HTTP-EQUIV <code>meta</code> tag. In fact, intrinsic events, such as <code>onclick</code>, are invalid in HTML4 if the default scripting language is not identified.</p>
<h2>Example</h2>
<p>This page sets the default scripting language to VBScript through a HTTP-EQUIV <code>meta</code> tag. Consequently, scripts that do not identify their type will be assumed to be VBScript.</p>
<p>The following buttons demonstrate an intrinsic event written in JavaScript that fails because the script type is not stated, thus it is assumed to be VBScript and so fails:</p>
<p>
<input type="button" value="VBScript (use VBScript)" onclick="vbscript:MsgBox 'Hello from VBScript'" />
<input type="button" value="VBScript (use default)" onclick="MsgBox 'Hello from VBScript'" />
<input type="button" value="JavaScript (use JavaScript)" onclick="javascript:alert('Hello from JavaScript');" />
<input type="button" value="JavaScript (use default)" onclick="alert('Hello from JavaScript');" />
</p>
<p><em>NB: this example will only work in Internet Explorer</em></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment