启动外部应用程序

Launch external application

本文关键字:应用程序 外部 启动      更新时间:2023-09-26

我正在构建一个本地web应用程序,我想用一个按钮启动一个外部应用程序。我在InternetExplorer的.html文件中找到了这段代码,但在show.html.erb中它不起作用,只显示错误消息

<script language="javascript">
function LaunchApp(appPath)
{
    try
    { 
        WSH = new ActiveXObject("WScript.Shell");
        WSH.run(appPath);
    }
    catch (ex)
    {
        errMsg = "An error occured while lauching the application.'n'n";
        alert(errMsg);
    }
    window.open('', '_self', '');
}
</script>
<button onclick="LaunchApp('C:''windows''system32''notepad.exe')">Click me</button>

是否可以启动应用程序?

这样的东西怎么样:

function LaunchApp(appPath)
  var oShell = new ActiveXObject("Shell.Application");
  var commandtoRun = appPath; 
  oShell.ShellExecute(commandtoRun,"","","open","1");
}