HTA and 'x-ua-compatible' meta tag

故事扮演 提交于 2019-11-26 23:17:51

问题


Added to post Jun-19-2014

Thanks Bond. Since you had IE9, I appreciate your test. Hopefully if somebody out there has IE 10 they will test it, too. It does not make any sense why under the IE 11 engine you can only run compatibility up to ie8.


I created this tiny, itty-bitty HTA in order to post it so hopefully I can find out what I am missing.

My system is a Win7 Pro 64bit with IE 11.

When I set the meta tag as:

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

the HTA runs peachy-keen. No problems. But when I change it to:

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

it doesn't run so good.

Now ... I know that there was a big family blow-out between IE 11 and VBScript. VBscript got booted out of the house for good. IE 11 refuses to communicate with it anymore. So I can understand why setting it to content="ie=edge" would not work. But why doesn't it work when setting it to content="ie=9"?

<!DOCTYPE html>
<head>
<meta http-equiv="x-ua-compatible" content="ie=8">
<hta:application
applicationname="Hmmmmmm"
singleinstance="yes"
id="oHTA"
>
<title>Huh? What?</title>
<script language="VBScript">

Option Explicit
Dim objFSO,file

Sub Window_OnUnLoad
   Set objFSO=CreateObject("Scripting.FileSystemObject")
   Set file=objFSO.OpenTextFile("c:\temp\submit.txt",2,True)
   file.Write oHTA.document.getElementById("aa").value
   file.Close
   Set objFSO=Nothing
   Set file=Nothing
End Sub

Sub Window_OnLoad
   window.ResizeTo 240,130
End Sub

Function Form_OnSubmit()
   window.Close
   Form_OnSubmit=False
End Function

</script>
</head>
<body style="margin:30px;">
<form id="form" action="">
<input id="aa" type="text" size="10" value="test">
<input type="submit" value="Submit">
</form>
</body>
</html>

Running it as ie8 set in the meta tag works fine ... window pops up, gets resized, and writes to the file on submit ... glory-be!

Running it as ie9 set in the meta tag ... window pops up, resizing is ignored, and writing to the file is ignored ... as if all the VBScript is being ignored.

What information am I missing?


回答1:


Looks like later versions of IE is not supporting HTA as mentioned in the other answers. One solution to your problem is: Make your HTA file navigable (HTA attribute navigable="yes") and do not specify any x-ua-compatible meta tags. In the HTA file navigate to another file which has the x-ua-compatible tag. The file you navigated will have the HTA priviliges:

HTA File:

<!doctype html>
 <html lang="en">
  <head>
   <HTA:APPLICATION 
    navigable="yes" />
  <script type="text/javascript">
  <!--
    document.location = 'htacontent.htm';
  //-->
  </script>
 </head>
 <body>
 </body>
</html>

htacontent.htm

<!doctype html>
<html lang="en">
  <head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
...



回答2:


I've just faced the same problem.

The solution is to put Window in lower case ! It is especially astonishing as usually VBScript is not case sensitive !

So declare Sub window_onLoad instead of Sub Window_onLoad, and so on... Finally your script should work. Tested on a Win7 Pro 64bit with IE 11, like yours.

IE strikes back !




回答3:


Later versions than IE9 aren't made to be compatible with HTA. So if you put the <meta http-equiv="x-ua-compatible" content="ie=9" /> tag, it won't support things for HTA like <hta:application>, VBScript or frames. I also have that problem and what I do is that I just try to work around the things that don't work in early versions of IE (for example see my answer to this question). You don't seem to use things that don't work in early versions of IE in the HTA that you posted. If you tell me exactly what you're using that doesn't work in IE7, I might be able to give you a workaround.




回答4:


as ced said before me, "The solution is to put Window in lower case", "So declare Sub window_onLoad instead of Sub Window_onLoad".

my issue came up when i use both js and vbs in a HTA. but after matching my case to my java "window.onload = function ()" sub everything works well together. vb itself is case-insensitive but this might be some mshta.exe specific behavior.




回答5:


I can confirm, (for some extremely odd reason); both CED and TRSyntax are on to something!
- Thanks by the way guys! - I'd have never 'guessed' this (and I thought I knew VBS quite well...)

Just as a quick bit of background information: I was simply trying to make my HTA prettier - it was already fully functional (this includes the fact I had my onload written literally as Window.OnLoad() and I added border-radius to my CSS and found it didn't work. - Bit of research suggested that I needed to add extra 'compatibility' via the Meta declaration of <meta http-equiv="x-ua-compatible" content="IE=Edge" />

Immediately after doing this my entire HTA's VBS broke - I tried different 'Content Modes' and discovered content="IE=8" allowed the VBS to work again but 'back to square one' in that it was ignoring the CSS for border-radius.

This is when I finally arrived here - it would seem that adding the meta makes interpretation of the VBS stricter which is perhaps why my OnLoad function was now invalid... (although a strange note is the fact my original Window.OnLoad() is invalid but window.OnLoad() is valid...) Merely changing the W on "Window" and keeping the same O for "On" fixed the problem, I presumed the "OnLoad" would also need changing to "onLoad" but this isn't the case...

So to summarise (to stop me waffling on too much) I will share my working settings:

Top of the document: <!DOCTYPE html>
I put this in for 'good practice' when making HTML5 based web pages, although it's not actually needed here with the meta declaration.

Within the <head>: <meta http-equiv="x-ua-compatible" content="IE=10" />
For some strange reason I get best overall results with IE=9 or IE=10. Any of the others seem to cause problems such as IE=8 breaks the CSS, IE=11 or IE=Edge seems to break the VBS

Within the <head><script>: Sub window_OnLoad()
Thanks to the kind folk on this page, I realised "Window" cannot contain any capitals, although after the dot; case no longer matters, eg: window.ONLOAD() is still valid & works but looks ugly...

Within the <head><style>:

table, th, td {
  border: 1px solid #000000;
  border-collapse: collapse;
  border-radius: 8px;
}

I just added this because I'm starting to waffle, but it might be useful to someone - it's just the CSS rule that puts a border on Tables, Table Headers & Cells and then if all else is working nicely the border will have rounded corners :D

Anyhow - many thanks to all - much respect to StackOverflow! - Maybe one day I'll sign up and make a real account :P



来源:https://stackoverflow.com/questions/24297029/hta-and-x-ua-compatible-meta-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!