Export (0) Print
Expand All

In the Beginning

As of December 2011, this topic has been archived. As a result, it is no longer actively maintained. For more information, see Archived Content. For information, recommendations, and guidance regarding the current version of Internet Explorer, see Internet Explorer Developer Center.

Mark Davis, Heidi Housten, Dan Mohr, Jay Allen, and Kusuma Vellanki
Microsoft Corporation

August 6, 2001

Kusuma kindly graced us with her writing one last time this month. But we are prepared for her departure. Allow us to present our newest gopher and, now what was it Kusuma did? Oh yes, writer! Please welcome Jay Allen to our team! He joins us with bleary eyes from the latest version of his progeny born just days ago.

This month we have a couple of long-winded answers for you. We look at calling functions between scripting languages, including conditional compilation, and delve even deeper into June's topic of compression and XML. Of course, we finish of with our usual assortment of shorts.

Welcome to the world Veda Rosella Mae Allen (already known as VRM VRM in the office)! Farewell, and thanks, Kusuma!

Contents

Can I Call You?—cross script calls
Don't Know (G)zip about XML—more (com)pressing XML

Web Team in Short

Can I Call You?

Dear Web Team:

In a recent article, you mentioned that JScript global functions, such as encodeURI and decodeURI, could be called from VBScript. Does this also mean that I can use VBScript functions, such as DateAdd and DateDiff, from JScript?

Also, where can I find when a function was added to a scripting engine, and what browsers they were distributed with?

Eric Falsken

The Web Team replies:

I'm glad you enjoyed the recent Web Team Talking article. You cannot call Microsoft Visual Basic® Script Edition (VBScript) functions directly from within Microsoft JScript® code. This is because of the difference between the data types used by each language:

  • VBScript has only one data type, the Variant, which can hold many different types of data.
  • JScript has primitive data types for string, number, and Boolean values, and reference data types for objects and arrays.

VBScript can interpret primitive JScript data types, so you can wrap the desired function in a custom VBScript function. This is demonstrated in the following sample code.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
var xmas = "December 25,2001";
function showToday()
{
  alert( "Today is " + Today() );
}
function showTomorrow()
{
  alert( "Tomorrow is " + Tomorrow() );
}
function showTime( date )
{
  alert( "The date is " + AnyTime( date ) );
}
function showDaysUntilXmas()
{
  alert( "" + DaysUntilXmas() + " days until Xmas" );
}
</SCRIPT>
<SCRIPT LANGUAGE="VBScript">
Function Today()
  Today = FormatDateTime( Date )
End Function
Function Tomorrow()
  Tomorrow = FormatDateTime( DateAdd( "d", 1, Date ) )
End Function
Function AnyTime(TheDate)
  AnyTime = FormatDateTime( CDate(TheDate) )
End Function
Function DaysUntilXmas()
  DaysUntilXmas = DateDiff( "d", Date, CDate(xmas) )
End Function
</SCRIPT>
</HEAD>
<BODY>
<BUTTON ONCLICK="showToday()">Display today's date</BUTTON>
<BUTTON ONCLICK="showTomorrow()">Display tomorrow's date</BUTTON>
<BUTTON ONCLICK="showTime(xmas)">Display another date</BUTTON>
<BUTTON ONCLICK="showDaysUntilXmas()">Display days until Xmas</BUTTON>
</BODY>
</HEAD>

For a comprehensive list of JScript and VBScript language elements, the version of the script engine providing support, and the host applications that implement each script engine, please check the following Web pages:

Ok, so now you know which functions are available in which script engine and browser, but how does this help you, the Web developer? Well, if you wish to use features available in more recent versions of the script engines, but also want to allow your Web page to display in down-level browsers, you can detect the version of the script engine and code accordingly.

Version 3.0, and later, of the Microsoft script engines provides the following functions to determine the script engine information:

  • ScriptEngine: Returns a string representing the scripting language.
  • ScriptEngineMajorVersion: Returns the major version number of the script engine.
  • ScriptEngineMinorVersion: Returns the minor version number of the script engine.
  • ScriptEngineBuildVersion: Returns the build version number of the script engine.

The advantage of using these functions is that they are available to both JScript and VBScript.

Version 2.0, and later, of the Microsoft JScript engine provides conditional compilation statements and variables that you can use to isolate version-specific script. Conditional compilation support is activated by specifying the @cc_on statement. Following this statement, you can use the @if, @elif, @else, and @end statements in conjunction with conditional compilation variables. By placing these statements in a comment, other browsers can ignore your conditional code.

The following sample code demonstrates how to use both features.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
// Example of conditional compilation
/*@cc_on @*/
/*@if (@_jscript_version >= 5.5)
   // Call function that is only available in script engine 5.5
@else @*/
   // Alert user that functionality is included in a more recent version of the script engine
/*@end @*/

function init()
{
var ver;
  // Example of script engine information functions
  if ( "undefined" == "" + typeof ScriptEngineMajorVersion )
    ver = "1";   // Function not available before version 2
  else
    ver = ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion();
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="init()">
</BODY>
</HEAD>

Don't Know (G)Zip about XML

Dear Web Team:

In your June 2001 response to XML in a Squeeze, you mentioned that it would be possible to compress XML using gzip and then pass this data to the browser with the http header:

Response.AddHeader "Content-Encoding", "gzip" 

I really like this idea. I have attempted to emulate this but am stuck on a problem. I compress the XML using a third-party component and sent it to the browser with the following headers:

Response.Buffer = true 
Response.Expires=-1
Response.ContentType="text/xml" 
Response.AddHeader "Content-Encoding", "gzip" 

All is well up to this point. The browser knows it is accepting XML and when I view the source of the page I can see the XML. However, the browser cannot render the XML. I get the following error:

A name was started with an invalid character. Line 1, Position 2 

Any pointers to help solve this will be greatly appreciated.

Adam Bate

The Web Team Replies:

Adam, consider yourself lucky—that sound you hear is the Four Horsemen of the Apocalypse passing you by. There are potential pitfalls associated with compressing XML data (which we will review below for the afflicted). However, the answer to your specific problem is straightforward, and unrelated to the use of Content-Encoding.

Your document is encoded as UTF-16-formatted Unicode; however, you're missing the Byte Order Mark (BOM) that identifies the byte order, or "endian-ness," of the data. If you open your XML file in a binary editor, you'll see that the least significant byte is listed first. This makes your data little-endian, the standard Windows byte ordering (and the default for Unicode). You can solve this either by ensuring that your XML files start with the proper BOM (0xFFFE), or by switching to UTF-8 encoding of your XML, which doesn't require the BOM. US-ASCII is a subset of UTF-8, so if you're primarily working with English data now, switching to UTF-8 is painless. If you're reading your XML files in from disk, and want to stay with UTF-16, adding the BOM is easy. Open the files in Notepad, select File, then Save As, and choose Unicode from the Save As dialog box Encoding drop-down. Check out this MSDN Library link for more information on XML and the various character encodings.

Also, as we hinted last time around, you can most likely cut out the third-party compression component. IIS will automatically compress both static and dynamic (ASP-generated) data if you know how to ask nicely. Open Internet Services Manager, and on the Properties tab for the machine (right-click machine name and select Properties), hit the Edit button for "WWW Service." This will invoke the Master Properties dialog. Select Service, and you will see a section entitled HTTP Compression. To encode all dynamic data, select Compress application files, then test it out using the following file:

<%
Response.ContentType = "text/xml"
Response.Expires = -1
Response.Write "<?xml version='1.0'?><parent><child /></parent>"
%>

If you use a network trace tool such as Windows® Network Monitor to view this transaction, you'll notice your data has been successfully compressed. We tested compression with both UTF-8-encoded and UTF-16-encoded files, and both worked well.

Now, this should work fine if you're viewing XML files directly in the browser. If you're trying to use compressed XML in a data island, or in script using the Microsoft.XMLDOM object—well, it's time to get ugly. There are, shall we say, complications for developers who must use down-level (prior to v3.0) versions of MSXML, and they relate to the networking architecture of Internet Explorer. Below MSHTML, the Internet Explorer DHTML rendering engine, resides URLMON (URLMON.dll). URLMON is 8-dot-3 shorthand for URL Moniker. Monikers (a fancy British word for names) are COM's design pattern for locating resources based on a unique name—in this case, a URL. URL Monikers hide the nasty details of network implementation from developers. These details, for HTTP, FTP and GOPHER URL monikers, are handled by another component, the Windows Internet Library, or WinInet (WININET.dll) for short, which handles the grunt work of formatting the HTTP request, making the remote connection with Winsock, and parsing the response from the Web server.

Prior to version 3.0, MSXML used the WinInet library directly. This spells trouble for XML data that uses Content-Encoding, as URLMON, not WinInet, is the component responsible for decompressing data. As of v3.0, MSXML is now using URLMON. If you want to take advantage of XML compression for XML accessed by script, make sure your clients have the latest XML redistributable installed on their machines.

Finally, our old article discussed compressing static XML files on disk. What we forgot to mention is that IIS does not compress XML/XSL files by default—only .html, .htm and .txt files. However, you can easily add new file types to the compression list using the handy tip in the Knowledge Base article Q234497.

Web Team in Short

Looking Back in History

Q: Dhiren Vyas wants to integrate the history folder functionality maintained by Internet Explorer when hosting the WebBrowser control.

A: Refer to information provided in our previous column on how to access the information in the history folder.

Wait a Minute!

Q: Madhura Changanty wants to know how to change the mouse to a wait cursor when executing lengthy scripts.

A: Refer to the article written by our DHTML Dude

Speaking…Writing in Tongues

Q: Sima Azar wants to set the charset of the HTML page to display Arabic.

A: Use the Windows-1256 charset. Refer to the Character Set Recognition documentation for detailed information.

VRML—A Virtual Reality

Q: Jerry Costa wonders whether he can view VRML pages in Internet Explorer.

A: Internet Explorer does not ship the VRML add-on anymore. You can use third party VRML viewers found on the Web, like VRWeb.

Learn How to Say NO

Q: Paul Fahey wants to prevent images on his page from being saved.

A: You can cancel the context menu for IMG elements. For Internet Explorer 6, set the galleryImg attribute to no to prevent the image toolbar from being shown since users can save the image using the toolbar.

Exchange On the Web

Q: Risto and Mike want to know if Microsoft Exchange information could be viewed on an ASP page.

A: Microsoft Exchange 2000 provides Outlook® Web Access components that can be integrated into your Web applications. Start by looking at New Development Features In Microsoft Exchange 2000.

Cancel Right Mouse Clicks

Q: Judy wants to cancel the right mouse click to prevent a user displaying a context menu on a Web page.

A: You need to handle the oncontextmenu event and return false from the handler function.

Shadowing Menus

Q: Eric and Wayne wanted to know how the MSDN Online Web developers produced the shadow effect on the new fly-out menus.

A: Have a read of last month's Web Team Talking column guys!

 

The Web Team

Mark Davis is a software design engineer on the Internet Explorer SDK team. Mark originates from England and is currently training to climb the major summits in the Northwest.

Heidi Housten works as a Consultant with Microsoft Consulting Services in Sweden after spending some time in Developer Support and MSDN. It is only a rumor that she moved there to escape the drizzle of Seattle; she really went for the traditional crayfish parties in August.

Dan Mohr, an engineer with Microsoft Developer Support's Internet Client team, spends his free minutes recording bands in his basement, programming his Commodore 64, and extolling the virtues of late '70s punk rock.

Kusuma Vellanki is one of the few people who likes winters in Washington better than summers. When not working as a developer for the Internet Client team, she can be found skiing down the slopes of Washington.

Jay Allen, a Support Engineer for the Internet Client team in Microsoft Developer Support, longs for the integration of Notepad and Emacs Lisp. What little time is not consumed by his four children is usually spent reading math books, studying Japanese and programming in Haskell.



The Web Team's Greatest Hits

List of Web Team Topics


  
Show:
© 2014 Microsoft