javascript 如何以编程方式在用户桌面上创建 Web 应用程序快捷方式?

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

How to create web app shortcut on user's desktop programmatically?

javascriptasp.netweb-applicationsclient-sideintranet

提问by Tejas

For enterprise intranet web application, is there any way to create a desktop shortcut of web application on user's desktop? I'm looking for functionality similar to Google Gears, but without installing Google Gears. I'm looking to give user's a link on web application that says "Click here to install desktop shortcut", when they click on it, a desktop shortcut is installed with the custom icon for our application. Is there a way to do it using javascript or any other client side technologies? I don't want to run any exe on user's machines. Even though it's intranet, I have to jump through lot of corporate hoops, compliance approvals, etc to run exe on their machine. We are trying to avoid that, due to time constraints.User machines are windows XP with IE6 installed. They may all upgrade within next year's time to Windows 7 with IE8. Intranet web application in question is developed using asp.net 3.5, c#.

对于企业内网web应用,有没有办法在用户桌面上创建web应用的桌面快捷方式?我正在寻找类似于 Google Gears 的功能,但没有安装 Google Gears。我希望在 Web 应用程序上为用户提供一个链接,上面写着“单击此处安装桌面快捷方式”,当他们单击它时,会为我们的应用程序安装带有自定义图标的桌面快捷方式。有没有办法使用 javascript 或任何其他客户端技术来做到这一点?我不想在用户的机器上运行任何 exe。即使它是内联网,我也必须跳过很多公司圈子、合规性批准等才能在他们的机器上运行 exe。由于时间限制,我们正在努力避免这种情况。用户机器是安装了IE6的Windows XP。他们可能会在明年的时间内升级到带有 IE8 的 Windows 7。有问题的 Intranet Web 应用程序是使用 asp.net 3.5、c# 开发的。

回答by NotMe

If this is really a corporate environment then just go talk to the network operations team.

如果这确实是一个企业环境,那么只需与网络运营团队交谈即可。

It should be trivial for them to add something to the login script to push this link to the people's desktops.

对他们来说,在登录脚本中添加一些东西以将此链接推送到人们的桌面应该是微不足道的。

More Info:
http://www.petri.co.il/forums/showthread.php?t=6154
http://social.technet.microsoft.com/Forums/en/winserverGP/thread/02a7bfbb-180f-40eb-82e3-2343b2bf31eb

更多信息:
http: //www.petri.co.il/forums/showthread.php? t =
6154 http://social.technet.microsoft.com/Forums/en/winserverGP/thread/02a7bfbb-180f-40eb- 82e3-2343b2bf31eb

回答by zzzzBov

Alright, at first I thought that this was an impossible task, until I realized that it's not.

好吧,起初我认为这是一项不可能完成的任务,直到我意识到并非如此。

A shortcut is just a file, and we all know you can download files from links.

快捷方式只是一个文件,我们都知道您可以从链接下载文件。

I'm not sure how well windows shortcuts can be transferred from computer to computer, but I would assume that a shortcut with a location like http://www.google.com/is not tied to any specific windows machine.

我不确定 Windows 快捷方式可以从计算机传输到计算机的效果如何,但我认为具有类似位置的快捷方式与http://www.google.com/任何特定的 Windows 机器无关。

You could zip the shortcut, and point the link to the location of the zip file. Tell the users to unzip the file and place the shortcut. You may be able to just serve the shortcut, but you'd have to give the right headers, and probably specify application/octet-streamor something like it.

您可以压缩快捷方式,并将链接指向 zip 文件的位置。告诉用户解压缩文件并放置快捷方式。您也许可以只提供快捷方式,但您必须提供正确的标题,并且可能指定application/octet-stream或类似的内容。

Alternatively you can tell them to right click, go to new -> shortcut, and copy-pasta the urlinto the locationbox.

或者,您可以告诉他们right click,转到new -> shortcut,然后将其复制urllocation框中。

Alternatively you could write a batch filefor the users to download that opens a url in the default browser.

或者,您可以编写一个批处理文件供用户下载,以在默认浏览器中打开一个 url。

I know it's not quite as direct as click-button -> receive baconbut it will work.

我知道它没有那么直接,click-button -> receive bacon但它会起作用。

回答by Raynos

Try looking at SaveAs

尝试查看SaveAs

document.execCommand("SaveAs", false, "url to desktop");

document.execCommand("SaveAs", false, "url to desktop");

The user will still have to click save and it only saves a HTML page. You would have to open a hidden IFrame containing a web application and call .execCommandon the iframe's document.`

用户仍然需要点击保存,它只会保存一个 HTML 页面。您必须打开一个包含 Web 应用程序的隐藏 IFrame 并调用.execCommandiframe 的文档。`

回答by Ross

You can create a shortcut (.lnk) file in a directory in your site and put it as the Url for a hyperlink so the users right click and save as they download the .lnk file. Your server will need the mime-type .lnk application/x-ms-shortcut adding.

您可以在站点的目录中创建快捷方式 (.lnk) 文件,并将其作为超链接的 Url,以便用户在下载 .lnk 文件时右键单击并保存。您的服务器将需要添加 mime 类型的 .lnk 应用程序/x-ms-shortcut。

The icon can be done by putting it on a network location and using the "Change icon" function to refer to this network location. This works on Windows. I suppose it could be adapted for each OS required?

图标可以通过将其放在网络位置并使用“更改图标”功能来引用该网络位置来完成。这适用于 Windows。我想它可以适应每个所需的操作系统吗?