JavaScript 书签图标

发布于 2024-10-05 06:13:50 字数 238 浏览 1 评论 0原文

我有一个网站,它提供了一个有用的书签链接,其中仅包含 javascript,而不是网页链接。例如 URL:“javascript:(function(){.....})();”书签栏中显示的图标是默认的空白纸张图像。

当有人将链接拖到书签栏时,是否有办法强制它具有我选择的图标,例如我网站的 favicon.ico? (例如,当您的书签是标准网址时,例如网址:“www.mysite.com”)

非常感谢您抽出时间!
jJ

I have a site which offers a useful bookmark link that contains javascript only as opposed to a link to a web page. eg URL:"javascript:(function(){.....})();" The icon that appears in the bookmarks bar is the default blank paper image.

Is there a way of forcing it to have an icon of my choice, eg the favicon.ico of my site, when someone drags the link to their bookmarks bar? (eg like when your bookmark is a standatd url such as URL:"www.mysite.com")

Many thanks for you time!
jJ

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人如玉 2024-10-12 06:13:50

这些书签称为小书签,仅供参考:)

不,没有办法为它们设置图标。这是因为浏览器会自动在书签指向的链接上查找图标。它找到该 favicon 的方法是访问页面本身并查看 HTML 中的元数据,或者访问 domain/favicon.ico

正如您所看到的,浏览器无法执行这些步骤一堆 JavaScript 代码。

Those bookmarkes are called bookmarklets, just FYI :)

And no, there is no way to set up an icon for them. This is because the browser automatically looks for the favicon on the link the bookmark is pointing to. The way it finds this favicon is by either accessing the page itself and looking at the meta data in the HTML, or alternatively by going to domain/favicon.ico

As you can see, there is no way for the browser to perform those steps on a bunch of javascript code.

方觉久 2024-10-12 06:13:50

我可能是错的,但我相信您必须通过书签至少访问该网站一次才能让它使用适当的图标更新您的书签。不过,您可以在标题中使用 link 元素并指定快捷方式的备用图标。

<link rel="shortcut" HREF="/shortcut.ico">

I could be wrong but I believe you have to visit the site at least once via the bookmark to have it update your bookmark with the appropriate icon. You can, though, use a link element in the header and specify an alternate icon for shortcuts.

<link rel="shortcut" HREF="/shortcut.ico">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文