简体   繁体   English

如何在不分析页面代码的情况下获取网站的收藏夹?

[英]How to get favicon of a website without analyzing page code?

I catch DOMContentLoaded event. 我捕获了DOMContentLoaded事件。 I have document that triggered the event. 我有触发事件的文件。 In the most cases the favicon can be obtained so: 在大多数情况下,可以获得网站图标,因此:

let favicon=gBrowser.selectedTab.image;

But if page is rather big user can has time to activate other tab. 但是如果页面很大,用户可以有时间激活其他选项卡。 In this case this code will obtain favicon of the new tab. 在这种情况下,此代码将获取新选项卡的图标。 I can obtain tab neighter for document nor for browser. 我可以为文档或浏览器获取标签页增强器。 Is it possible to obtain favicon without analyzing page code? 是否可以在不分析页面代码的情况下获取网站图标? Thanks in advance 提前致谢

yep use PlacesUtils, just use the domain name of the page, you don't have to wait for page to load to get that. 是的,使用PlacesUtils,只需使用页面的域名即可,而无需等待页面加载即可。 get it from document.location 从document.location获取

var {interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
var uri = Services.io.newURI('http://www.bing.com/', null, null);

var callback = function(uri, len, data, mimeType) {
      alert(uri.spec);
      console.log(uri.spec);
}





PlacesUtils.favicons.getFaviconDataForPage(gBrowser.currentURI, callback );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM