HTML Applications: Giving WSH a User Interface - Creating your first HTA
(Page 2 of 4 )
Like all other scripts, HTAs are nothing more than simple text files. They use the .hta file extension and can be executed directly. They take the form of an html file. Those of you familiar with browser scripting will find making the transition very easy.
You’ll be able to take advantage of both the WSH environment as well as the browser DOM. Since HTAs execute in a subset of Internet Explorer, you’ll also be able to do most anything the browser itself can do. That means (among other things) that you have XHTML, HTML, CSS, and JavaScript at your disposal. If you can do it inside your browser, chances are good that you can do it in an HTA as well.
A basic HTA script looks quite similar to a traditional HTML page. There are two things that I find quite refreshing about HTAs as opposed to web development. In an HTA, you’re always using Internet Explorer. This eliminates a need for cross-browser compatibility. Second, you don’t have to concern yourself with validation. While I recommend getting used to XHTML’s “table-less” design, you can freely use them in HTAs and no one will ever know the difference.
<html>
<head><title>My HTA</title>
<HTA:APPLICATION ID="oHTA";
APPLICATIONNAME="Visual Ping";
BORDER="thin";
BORDERSTYLE="normal";
SINGLEINSTANCE="no";
/>
</head>
<body>
</body>
</html>
As you can see, an HTA is constructed of simple HTML. The only difference is the inclusion of the HTA:APPLICATION object. The addition of this object is what allows you to use the HTA DOM. You can set its exposed properties in the form of attributes. For a complete list of attributes, please visit the MSDN HTML Application Reference.
Notice the inclusion of the ID attribute. This allows us to assign a reference to the HTA:APPLICATION object. You will use this reference later in your script whenever you need to access the properties or methods associated with the HTA DOM.
This code doesn’t do much at this point. A blank page isn’t very useful. We need to add some HTML.
We’re going to make an HTA that performs a simple ping operation. It will then return the result back into our window. But before we get too involved, let’s get some simple stuff out of the way.
Next: Building the page >>
More Windows Scripting Articles
More By Nilpo