That's not quite right: A bookmarklet has no domain, but it has a location (which is the bookmarklet itself) and you can assign an icon to that. After that it's a matter of how the browser saves icons (Firefox saves a bookmark's icon permanently, you may not be so lucky with other browsers).
It's possible to assign and modify favicon the favicon using javascript and canvas (see the amazing favicon game 明星队的守护者). The source code of the game will help you do that (it basically rely on use of toDataUrl() function on canvas as seen on line 554 of the source).
// set favicon
if( !stupidBrowser && useIcon )
{
var icon=$('favicon');
(newIcon = icon.cloneNode(true)).setAttribute('href',ctx.canvas.toDataURL());
icon.parentNode.replaceChild(newIcon,icon);
}
Unfortunately it only works for certain cases (more below).
工作原理:
(至少在 Chrome 中)它类似于书签小工具,使用 javascript: "<html>...your html code here, including a javascript tag that will run when loaded...</html>"格式,就像其他解决方案所建议的那样。在这种情况下,你在 将被取代页面上的 html 通过 bookmarklet 上的 html,但是 地点没变和 bookmarklet 本身仍然没有一个位置,所以 Chrome 不能为它保存一个收藏夹图标。
When you click it, it leaves the current page and loads the page in the 资料. Therefore you won't be able to use it for bookmarlets that interact with the current page, only for code that you can execute in a different page.
不要使用//作为评论。因为它们都将保存在一行中,所以将它们包装在/* */中,并且不要忘记使用分号
In FF it saved the favicon, but I was not able to set it to always open popup windows if I want to use window.open() because it doesn't allow me to save a default behaviour for data urls