IE as a platform for html apps

I came across HTA (HTML Applications) a while ago and I have to say it’s kinda neat.
In a way it’s not a big deal, but I didn’t know you could do this, and it really empowers you to write neat little apps fast by using JScript or VBScript and HTML, which is basic knowledge for a web developer right?

You can already write small apps in plain HTML pages, that’s right, but now and then you run into the problem that you need to do something your browser won’t let you because of security restrictions, and it’s damned right not to let you! For instance you’re trying to access an XML file on your hard drive. No biggy, but you won’t allow anyone to access your file system now will you?

I thought so, but in this case you want it, cause you’re writing the damn app yourself, and you trust yourself for the full 100%… well, mostly anyway. So here comes the “trick”. You rename your .html page (cause .htm is for FrontPage lusers) to .hta ét voilà, you’re basically finished. Now you can double click the HTA file, and see your page run as a full fledged Windows application, using good old fashion HTML for the interface and JavaScript as your programming language by choice. You could also use VBScript, but seriously.. why would you do that? Well, almost full fledged, but you can get pretty close by using the HTA tag defined in the pages head section.

How it works is that your newly created HTA page is running inside a seperate instance of Internet Explorer, with all those typical security restrictions turned off as your running it as a trusted application now. So you’re free to create any available ActiveX objects to do all sort of stuff like accessing the file system (FileSystemObject), parse XML files (MSXML2), access remote web pages (XMLHTTP), run stuff in shell commands (WShShell), you name it.

Another cool thing with these HTA pages is that it even supports command line parameters. So you can write one and launch it from a command shell, with a few command line options, to do some funky shiznit for you.

“Ok”, you say, “This is neat, but can’t I just write a simple .JS or .VBS script if I want to use command line stuff anyway?” Well yes you could, but there’s one advantage to the HTA approach, and that’s the fact that you can include other scripts using the HTML script tag, so you can finally create some handy libraries to do the mundane stuff for you.

There’s no way to do that in a plain .js or .vbs script, which sucks IMO, since after you’ve written a few of those, you realise you keep needing the same kind of functionality over and over again, which would be ideal to put in a library… which you can’t include… so you copy paste… blegh…

But anyway, if you feel like slapping together a quick app maybe give this HTA thing a shot. You might dig it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.