DHTML Lab: JavaScript Enhancement with VBScript | 11
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" TYPE="text/vbscript"> <!-- ' VB statements go here --> </SCRIPT>
Already, you should have noticed two differences from the JavaScript standard:
- Lines are commented with a single quote ('), not double slashes (//)
- 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()">Execute JS</A> <A HREF="somelink.html" LANGUAGE="VBScript" onClick="vbFunction()">Execute VB</A>
Navigator Behavior
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 Behavior
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()">Execute JS</A> <-- LANGUAGE attribute omitted; identified as JS (default) <A HREF="somelink.html" LANGUAGE="VBScript" onClick="vbFunction()">Execute 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()">Execute JS</A> <-- LANGUAGE attribute overrides default; <A HREF="somelink.html" onClick="someFunction()">Execute JS</A> <-- LANGUAGE attribute omitted; identified as JS (default) </BODY> </HTML>
Simple Rules
- Place a JavaScript SCRIPT tag first on your page to establish it as the default scripting language for Explorer.
- Use VBScript only in SCRIPT tags
- Use JavaScript to conditionally call VBScript functions
These three pointers will allow us to selectively use VBScript in a cross-browser page.
It's time to create our first VBScript function.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.Created: Nov. 18, 1998
Revised: Nov. 18, 1998
URL: https://www.webreference.com/dhtml/column22/js-vbTags.html