JavaScript version in HTA
Asked Answered
T

1

15

Does anyone know what version of JavaScript is used by HTA files.

Currently creating some script files - and trying to make use of Object.defineProperty

When running as an HTA - it errors stating that Object doesn't support this property or method. I've run it as an HTM file just to check - and there is no problem at all.

So I can only assume that mshta.exe is using an older JavaScript engine. Can any one confirm this?

Tris answered 24/10, 2013 at 13:48 Comment(0)
B
22

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.

Bluish answered 24/10, 2013 at 15:50 Comment(6)
Whenever I use the meta tag, my hta:application properties don't work. If I comment it out then they do. Is there a solution?Gayl
Unfortenately I've not a good solution for this. Since IE10, it seems, that many of HTA properties are not applied anymore (In the parsed code the HTA tag is moved to body). In IE9 they still seem to be respected. I've mostly used IE=9 instead of IE=edge, which gives at least modern event handling and the most of the HTML5 tags, including svg and canvas.Bluish
IE=9 works perfectly! I hope this is fixed at some point, but it's doubtful as they seem to be phasing this out. I wouldn't be surprised if the next version of Windows doesn't support HTA files.Gayl
@Bluish however only IE11 supports such CSS features as flex module, gradient and othersGilburt
@Gilburt True, but you've to compromize when working with obsoleted techniques = ). You've to make a choice between modern HTML features and HTA features, unfortunately you can't get both. That is also a subject in my answer: "hence everything said later about JS versions, stands for box-models, positioning, CSS etc, and available APIs and HTML elements too."Bluish
@Gayl Note that you can hack around this, by having the HTA tag and properties in one file and setting NVAIGABLE=yes, and having your HTML in a separate file. You can then use window.location within the HTA to navigate to your HTML file, and the HTML file will use the latest IE appropriate for the page.Dioxide

© 2022 - 2024 — McMap. All rights reserved.