JavaScript 书签图标
我有一个网站,它提供了一个有用的书签链接,其中仅包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些书签称为小书签,仅供参考:)
不,没有办法为它们设置图标。这是因为浏览器会自动在书签指向的链接上查找图标。它找到该 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.
我可能是错的,但我相信您必须通过书签至少访问该网站一次才能让它使用适当的图标更新您的书签。不过,您可以在标题中使用
link
元素并指定快捷方式的备用图标。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.