JavaScript Version in Hta

JavaScript version in HTA

The used JavaScript (or JScript) version depends on three things: installed Interner Explorer version, used document type declaration (DTD) and x-ua-compatible meta tag.

Though HTAs are run by mshta.exe, IE provides the JavaScript and rendering engines to applications, hence everything said later about JS versions, stands for box-models, positioning, CSS etc, and available APIs and HTML elements too.

If you have IE11 installed into your system, you can use the latest version of JavaScript by using <!DOCTYPE html> and <meta http-equiv="x-ua-compatible" content="ie=edge" />.

Naturally, setting the content to IE=edge doesn't override an old version of the installed IE, the latest available mode is used. Instead of edge, you can use IE version numbers to downgrade the app when run with newer IEs.

Omitting DTD should always drop the app to run in Quirks mode, which in the case of HTA is similar to IE5. However, in this case, the document mode can be altered with x-ua-compatible, but there were some inconsistencies at least in IE8 & 9. It's always safest to use DTD, if the Quirks mode isn't required.

With DTD, but without x-ua-compatible meta tag HTAs are run in IE7 Standards mode (which doesn't support object.defineProperty(), it's introduced in IE9).

You can read more about the subject at MSDN: Introduction to HTML Applications (HTAs)

IE version info for JS and CSS can be found at MSDN:

JavaScript version information

CSS Compatibility in Internet Explorer

Here's a "safe start" for a HTA file, when you want to use the latest available version:

<!DOCTYPE html>
<html>
<head>
<title>HTA</title>
<meta http-equiv="x-ua-compatible" content="ie=edge" />
// All link, style and script tags, or any code should be placed below the five lines above

You can also use ScriptEngine functions to find out the latest script version:

ver = ScriptEngine() + ' V ';
ver += ScriptEngineMajorVersion() + '.';
ver += ScriptEngineMinorVersion() + '.';
ver += ScriptEngineBuildVersion();
alert(ver);

Notice, that this shows only the latest version provided by browser, document mode doesn't have an affect to the returned values.

How to select the version of Internet Explorer for HTA (Html application)?

try:

<meta http-equiv="x-ua-compatible" content="IE=7">

or other versions :

<meta http-equiv="x-ua-compatible" content="IE=8">

or

<meta http-equiv="x-ua-compatible" content="IE=9">

or

<meta http-equiv="x-ua-compatible" content="IE=10">

or

<meta http-equiv="x-ua-compatible" content="IE=edge"> 

Is there an HTA-like solution for modern web apps?

The good news, is that it does exist, but it's not as "out-of-the-box" as HTA.

My team has migrated from HTA to WebView2.

The overall approach is to build a program with the WebView2 browser (you're basically building your own HTA like browser). Your javascript code can communicate back and forth with the program, which in turn has full access to local resources.

WebView2 is the Microsoft Edge Chromium browser, so you're getting the latest web tech and layouts (a big pain for HTA dev.). The program that contains the WebView2 control has full access to local files, scales, printers (without a pop-up dialog).

The approach has all the benefits of HTA (html / javascript programming, local file access, web based deployment, etc.), plus all layout and other benefits of a modern browser.

The program you'll build is very small, especially compared with the HUGE runtime of similar solutions, like Electron.

Rick Strahl has an excellent article on WebView2, and tips for building the program I'm describing. He has great advice on how to build an installer for it, including "Evergreen", which keeps the WebView2 up-to-date with the latest browser tech.

Microsoft's introduction to the technology here.
https://learn.microsoft.com/en-us/microsoft-edge/webview2/

Can I display the IE compatibility version of a HTA inside itself?

In IE8 and later, you can retrieve document.documentMode. It gives you a number representing the current document mode, 5 for quirks-mode, 6 for IE6 etc.

In IE6-7 there was document.combatMode, which returned a string telling you whether the standards-compliant mode is switched on or not.

Notice, that ScriptEngine returns the latest available JScript version, the used document mode doesn't change the values.



Related Topics



Leave a reply



Submit