spacer

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

home / experts / dhtml / column22
Developer News
Google Going Native With Chrome
Mozilla Fixes Firefox Flaws as 3.5 Release Nears
Microsoft and Novell Still Bosom Buddies

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" TYPE="text/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()">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

  1. Place a JavaScript SCRIPT tag first on your page to establish it as the default scripting language for Explorer.
  2. Use VBScript only in SCRIPT tags
  3. 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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
XML and PHP Simplified · Creating a ASP.NET Contact Form · Data Filtering with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Intel to Host Live Nehalem Q&A · 12 Tips to Troubleshoot Network File-Sharing · 10 Tips for Selling on Kijiji

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

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