启动外部应用程序

时间:2015-11-19 14:15:34

标签: javascript ruby-on-rails

我正在构建一个本地Web应用程序,并且我想使用按钮启动外部应用程序。 我发现这个代码在.html文件中使用Internet Explorer,但在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>

是否可以启动此应用程序?

1 个答案:

答案 0 :(得分:0)

这样的事情怎么样:

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