Get url favicon with Jquery -
i found script allows display favicons based on url on here: andreaslagerkvist
its pretty simple script, there example when copy/paste example doesn't seem work..please take @ demo: jsfiddle
what doing wrong? missing in script?
you never called plugin, defined it.
plugin definition
jquery.fn.favicons = function (conf) { var config = jquery.extend({ insert: 'appendto', defaultico: 'favicon.png' }, conf); return this.each(function () { jquery('a[href^="http://"]', this).each(function () { var link = jquery(this); var faviconurl = link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1') + '/favicon.ico'; var faviconimg = jquery('<img src="' + config.defaultico + '" alt="" />')[config.insert](link); var extimg = new image(); extimg.src = faviconurl; if (extimg.complete) { faviconimg.attr('src', faviconurl); } else { extimg.onload = function () { faviconimg.attr('src', faviconurl); }; } }); }); };
plugin invocation
jquery('#jquery-favicons-example').favicons({insert: 'insertbefore'});
here's a working fiddle.
Comments
Post a Comment