DHTML Lab: JavaScript Enhancement with VBScript | 2 | WebReference

DHTML Lab: JavaScript Enhancement with VBScript | 2


Logo

JavaScript Enhancement with VBScript
using the LANGUAGE attribute

 

The SCRIPT Tag

As you know, or can easily guess, to include VBScript in our page, we enclose it in the SCRIPT tag with a LANGUAGE attribute value of "VBScript":

<SCRIPT LANGUAGE="VBScript">
<!--
' VB statements go here
-->
</SCRIPT>

Already, you should have noticed two differences from the JavaScript standard:

  1. Lines are commented with a single quote ('), not double slashes (//)
  2. The HTML comment end tag (-->) is not preceeded by a script comment, just like with the <STYLE> tag.

The LANGUAGE Attribute

The new HTML4 standard foresees the use of multiple scripting languages in a single page. Since scripts can exist outside of the SCRIPT tag, as in the case of event handlers, the LANGUAGE attribute can be used in any tag to denote the script language used. For example:

<A HREF="somelink.html" LANGUAGE="JavaScript" onClick="jsFunction()"&gtExecute JS</A>
<A HREF="somelink.html" LANGUAGE="VBScript" onClick="vbFunction()"&gtExecute VB</A>

Navigator Behaviour

Navigator does not support VBScript, nor does it support the LANGUAGE attribute in tags other than SCRIPT. It is, therefore, not advisable to use VBScript outside of the SCRIPT tag. As we will see further on, JavaScript can be used to call a VBScript function, allowing both browsers to co-exist.

Explorer Behaviour

Explorer recognizes both languages, but considers JavaScript to be the default scripting language. The default language, however, is automatically changed to reflect the first language used on a page.

Example1:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"> <-- JS established as default
...
</SCRIPT>
<SCRIPT LANGUAGE="VBScript"> <-- LANGUAGE attribute makes VBScript kick in;
                                 overrides default
...
</SCRIPT>
<SCRIPT> <-- LANGUAGE attribute omitted; identified as JS (default) 
...
</SCRIPT>
</HEAD>
<BODY>
<A HREF="somelink.html" onClick="jsFunction()"&gtExecute JS</A>
           <-- LANGUAGE attribute omitted; identified as JS (default) 
<A HREF="somelink.html" LANGUAGE="VBScript" onClick="vbFunction()"&gtExecute JS</A>
           <-- LANGUAGE attribute overrides default; 
</BODY>
</HTML>

Example2:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="VBScript"> <-- VB established as default
...
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript"> <-- LANGUAGE attribute makes JavaScript kick in;
                                   overrides default
...
</SCRIPT>
<SCRIPT> <-- LANGUAGE attribute omitted; identified as VB (default) 
...
</SCRIPT>
</HEAD>
<BODY>
<A HREF="somelink.html" LANGUAGE="JavaScript onClick="someFunction()"&gtExecute JS</A>
           <-- LANGUAGE attribute overrides default;
<A HREF="somelink.html" onClick="someFunction()"&gtExecute JS</A>
           <-- LANGUAGE attribute omitted; identified as JS (default)
</BODY>
</HTML>

So, first let's look at how communication is established.

So, as usual, let's start with a look at our parameter variables.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Nov. 18, 1998
Revised: Nov. 18, 1998

URL: http://www.webreference.com/dhtml/column22/js-vbTags.html