Javascript 如何在客户端启动桌面应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6265717/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:00:57  来源:igfitidea点击:

how to start up a desktop application in client side

javascript

提问by hguser

In my web page, I have to start a desktop application on the client's computer if it's installed. Any idea how I can do this?

在我的网页中,如果安装了客户端计算机,我必须在客户端计算机上启动桌面应用程序。知道我该怎么做吗?

If the application is MS Office or Adobe Reader, I know how to start them, but the application I want to start is a custom application. You can not find it on the internet.

如果应用程序是 MS Office 或 Adob​​e Reader,我知道如何启动它们,但我要启动的应用程序是自定义应用程序。你无法在互联网上找到它。

How can I open the application?

如何打开应用程序?

采纳答案by retrodrone

The browser sandbox prohibits you from executing local resources, for good reason - to thwart a website destroying your box with malicious code. I've been researching the same functionality.

浏览器沙箱禁止您执行本地资源,这是有充分理由的 - 以阻止网站使用恶意代码破坏您的盒子。我一直在研究相同的功能。

The only solution I've found is to build an extension in Mozilla Firefox which can launch your app. Extensions live outside the sandbox so they can execute local resources. See this pagefor how to do that. You may be able to do it cross-browser using crossrider, though I haven't had success with that yet.

我找到的唯一解决方案是在 Mozilla Firefox 中构建一个可以启动您的应用程序的扩展程序。扩展位于沙箱之外,因此它们可以执行本地资源。请参阅此页面了解如何执行此操作。您可以使用crossrider跨浏览器完成此操作,尽管我还没有成功。

You could alternatively build a thick client populated from a web service, and launched from the browser through an extension as mentioned above. This is what I'm doing to get around the sandbox. I'm using local XULfor this.

您也可以构建一个从 Web 服务填充的胖客户端,并通过上述扩展从浏览器启动。这就是我为绕过沙箱所做的工作。为此,我正在使用本地 XUL

See my questionfor additional discussion.

有关其他讨论,请参阅我的问题

回答by RaYell

Basically it's not possible to achieve unless an application registers a protocol that will trigger it. If it does that all you need to do is to provide a link using this protocol

除非应用程序注册将触发它的协议,否则基本上不可能实现。如果这样做,您需要做的就是使用此协议提供链接

yourcustomapp://some.parameters

yourcustomapp://some.parameters

Another way the 3rd party app can integrate with the browser is if it hooks to it as a plugin. This is how flash apps work etc.

3rd 方应用程序可以与浏览器集成的另一种方式是将其作为插件挂钩。这就是 Flash 应用程序的工作方式等。

If the app you are trying to launch does not support something like that it's going to be close to impossible to achieve what you want.

如果您尝试启动的应用程序不支持类似的功能,则几乎不可能实现您想要的功能。

回答by symcbean

First off - you can't do it using javascript in any sort of a portable mechanism.

首先 - 你不能在任何类型的便携式机制中使用 javascript 来做到这一点。

If the application is ms office or adobe reader,I know how to startup them

如果应用程序是 ms office 或 adobe reader,我知道如何启动它们

No you don't - you know how to send a document, which the browser associates with these applications and invokes them supplying the name of the local copy of the response. You can't just start the programs.

不,您不知道 - 您知道如何发送文档,浏览器将其与这些应用程序关联并调用它们并提供响应的本地副本的名称。你不能只是启动程序。

You just need to do the same for your app - invent a new mime type (the major type would be 'application' and by convention, non-standard minor types are prefixed with 'x-', so you might use application/x-hguser) then associate that mimetype with the relevant program browser side.

你只需要为你的应用程序做同样的事情——发明一个新的 mime 类型(主要类型是“应用程序”,按照惯例,非标准次要类型以“x-”为前缀,所以你可以使用 application/x- hguser) 然后将该 mimetype 与相关的程序浏览器端相关联。

i.e: You need to explicitly configure each browser

即:您需要明确配置每个浏览器

回答by Ivandolchevic

I already encouter that problem in some complex production environnements.

我已经在一些复杂的生产环境中遇到了这个问题。

I do the trick using the following code :

我使用以下代码来解决这个问题:

function launch(p_app_path)
{
   var oShell = new ActiveXObject("WScript.Shell");
   oShell.Run('"' + p_app_path + '"', 1);
}

In IE options > Security > Customize the level > ActiveX controls and plugins > Initialization and script ActiveX controls not marked as safe for scripting, set the value to Askor Active.

在 IE选项 > 安全 > 自定义级别 > ActiveX 控件和插件 > 初始化和脚本 ActiveX 控件没有标记为安全的脚本,将值设置为询问活动

It isn't a security problem when your website is enclosed into a specific security context. And as they say, it's not worth it to build a gas plant.

当您的网站包含在特定的安全上下文中时,这不是安全问题。正如他们所说,建造天然气厂是不值得的。

回答by retrodrone

I'm actually having a lot of success right now with SiteFusion. It's a PHP client/server application framework that serves out XUL/JavaScript applications from a server deamon running in Apache. You access applications from a very thin client in XULRunner, or potentially off a web page using extensions. Clients can execute on any platform, and they're outside of the browser sandbox so you can access local resources such as executables. It'a a fairly elegant solution, their website provides great examples and documentation, and their forum is very responsive. I actually found a minor bug in passing arguments to local executables, posted a question about the forum, and it was fixed by the chief developer in under 15 minutes. Very impressive, overall!

实际上,我现在使用SiteFusion取得了很大的成功。它是一个 PHP 客户端/服务器应用程序框架,可从运行在 Apache 中的服务器守护进程提供 XUL/JavaScript 应用程序。您可以在 XULRunner 中从非常瘦的客户端访问应用程序,或者可能使用扩展从网页上访问应用程序。客户端可以在任何平台上执行,并且它们在浏览器沙箱之外,因此您可以访问本地资源,例如可执行文件。这是一个相当优雅的解决方案,他们的网站提供了很好的示例和文档,而且他们的论坛反应灵敏。我实际上在将参数传递给本地可执行文件时发现了一个小错误,在论坛上发布了一个问题,首席开发人员在 15 分钟内修复了它。非常令人印象深刻,总体而言!

回答by David

JavaScript alone can't do this. (No, not even with MS Office or Adobe Reader.) Thankfully.

单靠 JavaScript 无法做到这一点。(不,即使使用 MS Office 或 Adob​​e Reader 也不行。)谢天谢地。

There are a number of old ways, including using ActiveX, which may work for your needs. As others have pointed out while typing this, you can customize responses based on the mime type or the protocol, etc.

有许多旧方法,包括使用 ActiveX,它们可能适合您的需要。正如其他人在输入时指出的那样,您可以根据 mime 类型或协议等自定义响应。

Any way you look at it, you're going to need control over the end users' browser. If you're in a close environment where you can dictate policy (users must use a specific browser, with a specific configuration), then you're going to need to do that. For an open environment with no control over the end users, you're out of luck.

无论您怎么看,您都需要控制最终用户的浏览器。如果您处于可以指定策略的封闭环境中(用户必须使用具有特定配置的特定浏览器),那么您将需要这样做。对于无法控制最终用户的开放环境,您很不走运。