Javascript - 以编程方式创建桌面链接 [英] Javascript - create desktop link programmatically

查看:133
本文介绍了Javascript - 以编程方式创建桌面链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式为我的网页创建桌面链接?

Is there a way to programmatically create a desktop link for my webpage?

推荐答案

不是来自Javascript,但有一个让用户这样做的技巧。它更像是一种交互设计技术,而不是编程技术,但我会写一下这个问题可能会有人搜索这个问题并发现它很有用。

Not from Javascript, but there is a trick to let the users do it. It is more of an interaction design technique rather than programming technique but I'll write it maybe someone googles this question and finds it useful.

在页面上创建一个图标,其下方有文字。然后要求用户将此图标拖到他们的桌面上。该图标应嵌入锚标记< a> ,其中 href 属性指向您的网站。图标下方的文字应与您网页的< title> 标记相同。当用户将锚点链接从页面拖动到文件夹,桌面或书签栏时,浏览器会生成一个图标。浏览器分配此快捷方式或链接的文本通常是页面的< title> 。请记住,应将图标设置为元素的背景,以便浏览器不会保存图像而不是创建新链接。如果此图标与您网站的 favicon 相同,那就更好了。

Make an icon on your page with a text under it. Then ask the user to drag this icon to their desktop. The icon should be embedded in an anchor tag <a> with the href attribute pointing to your website. The text under the icon should be the same as the <title> tag of your page. The browsers make an icon when the user drags an anchor link from a page to a folder, desktop or bookmark bar. The text that the browsers assign this shortcut or link is usually the <title> of the page. Remember that the icon should be set as the background of the element so that the browser doesn't save the image instead of making a new link. It would be even better if this icon is the same as the favicon of your website.

为了演示此技术,这里有一些代码:

To demonstrate this technique here is some code:

<p>You can make a shortcut to www.mysite.com by dragging this icon to your desktop or bookmark bar: </p>
<a href="https://www.example.com">
  <div id="icon" style="background-image:url('favicon.png');width:32px;height:32px;"></div>
  <div id="title">www.example.com</div>
</a>

与原生应用类似:

在Chrome中,用户可以转到菜单>更多工具>创建应用程序快捷方式... ,并为您的网站创建一个看似应用的无边框快捷方式。类似的东西可以在Android,iOS和Android上的Firefox中完成。

In Chrome users can go to Menu > More tools > Create application shortcut... and create a borderless shortcut to your site that looks like an app. Something similar can be done in Android, iOS and also Firefox on Android.

这篇关于Javascript - 以编程方式创建桌面链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆