0

I have a .HTA file with JS like this:

<script>
var fso = new ActiveXObject('Scripting.FileSystemObject');
var configsHandle = fso.OpenTextFile('configs.json', 1);
var configs = configsHandle.ReadAll();
configsHandle.Close();
alert(configs);
</script>

and my configs.json is

{"default":{"content":"main"}}

I can successfully get content of the json file as a string. But I can't convert it to JSON with JSON.stringify() and then to parse it with JSON.parse() because I get the error

JSON is undefined

and I don't know how to convert the string to an object / array and then to parse it at least as an associative array with

alert(configs['default']['content']);

ps. I need it to be working on Microsoft HTML Apllication host program of Win7 (i.e. not in Chrome and not in Linux or other OS)

stckvrw
  • 1,689
  • 18
  • 42
  • 1
    Use a newer IE version to get JSON support. See https://stackoverflow.com/a/19570684/1169519 – Teemu Apr 18 '18 at 11:11
  • I have IE 8 installed on my Win7 and if I open simple html page with JS `alert(navigator.userAgent)` by this IE, I see MSIE **8.0**. But if I open hta page with the same `alert()` by my Microsoft HTML Apllication host program, I see MSIE **7.0**. Why and how can I make IE 8 to be used by HTA host program? – stckvrw Apr 19 '18 at 20:42
  • 1
    The answer is in the post I've linked above. "_If you have IE11 installed into your system, you can use the latest version of JavaScript by using ` ` and ``. Naturally, setting the content to `IE=edge` doesn't override an old version of the installed IE, the latest available mode is used._" Which in your case is IE8, which supports JSON. – Teemu Apr 20 '18 at 04:15
  • There is a problem: I need to detect which IE is used but as I said above, I still get `alert()` with IE7 while after adding the `x-ua-compatible` meta tag JSON is supported i.e. now IE8 is used. So how can I get the correct version of IE is used? With `ScriptEngine` functions you mentioned in your answer, I also get the same `JScript 5.8.17514` in both cases: with the meta tag and without it. – stckvrw May 06 '18 at 21:48
  • Just put the `x-ua` as `edge`, then you know IE8 is used. Also mentioned in the linked answer: "_... document mode doesn't have an affect to the returned values_". If you're going to create HTAs using JS, I'd suggest you to update the browser to IE9, that's a lot more modern than IE8, and the last with full support of HTA. – Teemu May 07 '18 at 04:12
  • Yes, my HTA file already has the meta tag and I read in your comment than IE9 is the best version to be used for HTA, even better than Edge. The point is different users with different versions of installed IE may download and use my HTA file in the future. So the file should display a warning like the app needs IE9 to be installed. But as I said, I don't know how to get the installed version and display such warning. – stckvrw May 07 '18 at 11:49
  • 1
    One way is to tell users the app requires IE9 or later before they download your app. In the app you can detect the used IE version using ScriptEngine functions, and if you detect a version smaller than 9, you can show a warning. For example IE11 installed in my machine returns 11.0.16384 with the snippet in the answer I've linked in my first comment. I'm not aware what other versions will return. – Teemu May 07 '18 at 12:10

0 Answers0