javascript 如何从 .html 文件中运行 .hta 文件而不要求下载它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16739539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run .hta file from within .html file w/o asking to download it
提问by sdnr1
I want to run .hta file from within .html file w/o the browser asking to download it.It should run in an iframe in the html page in the browser. The code i am using is this-
我想在没有浏览器要求下载它的 .html 文件中运行 .hta 文件。它应该在浏览器的 html 页面的 iframe 中运行。我使用的代码是这样的-
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe src="app.hta">
</body>
</html>
The problem is that the browser asks to download the hta file but it want that it should run automatically.
问题是浏览器要求下载 hta 文件,但它希望它应该自动运行。
The hta file code is this-
hta 文件代码是这样的——
<html>
<head>
<title>Application Executer</title>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Application Executer"
BORDER="no"
CAPTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="no"
WINDOWSTATE="normal">
<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/app.exe", 1, false);
}
</script>
</head>
<body>
<input type="button" value="Run Notepad" onclick="RunFile();"/>
</body>
</html>
回答by Teemu
Actually you can't open a HTAwithin iframe
even if the main app was a HTA. HTAs have their own OS windows, just like a browser or any .exe has.
其实你可以不打开HTA内iframe
即使主应用程序是一个HTA。HTA 有自己的操作系统窗口,就像浏览器或任何 .exe 一样。
What you can do, is to put your script to a regular html file. Depending on the security settings of IE, it executes the code, or ask user to allow to execute, or throws an error.
你可以做的是把你的脚本放到一个普通的 html 文件中。根据 IE 的安全设置,它执行代码,或要求用户允许执行,或抛出错误。
Notice also, that ActiveX
s work only in Internet Explorer. And like Dark Falcon has said, allowing ActiveX
execution from web would be a huge security risk. So trying to do these kind of things at a public website is not recommended.
另请注意,这ActiveX
仅适用于 Internet Explorer。正如 Dark Falcon 所说,允许ActiveX
从网络执行将带来巨大的安全风险。因此,不建议尝试在公共网站上执行此类操作。
If this is an intranet app, you can change the main app to HTA. Then you can add Run Notepad
button (and the script) to the main app, or to an iframe
, which has application=yes
set. Also trusted sites (html) can run ActiveX
s without prompting or errors.
如果这是一个内网应用程序,您可以将主应用程序更改为 HTA。然后您可以将Run Notepad
按钮(和脚本)添加到主应用程序,或添加到iframe
已application=yes
设置的 。受信任的站点 (html) 也可以在ActiveX
没有提示或错误的情况下运行。
回答by Dark Falcon
HTAs cannot be run under the browser. They run under a special host process called mshta
. Allowing opening of an HTA in a browser frame would be asking for problems, as HTAs have much higher privileges than normal web pages.
HTA 不能在浏览器下运行。它们运行在一个名为mshta
. 允许在浏览器框架中打开 HTA 会带来问题,因为 HTA 具有比普通网页高得多的权限。