It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




7年前关闭。




考虑到收藏夹图标并不总是位于基本URL上,我需要一种从通用网页获取收藏夹图标URL的方法。

P.s.无需使用外部服务或库。

最佳答案

这似乎可行:

var getFavicon = function(){
    var favicon = undefined;
    var nodeList = document.getElementsByTagName("link");
    for (var i = 0; i < nodeList.length; i++)
    {
        if((nodeList[i].getAttribute("rel") == "icon")||(nodeList[i].getAttribute("rel") == "shortcut icon"))
        {
            favicon = nodeList[i].getAttribute("href");
        }
    }
    return favicon;
}

alert(getFavicon());​

或查看http://jsfiddle.net/PBpgY/3/作为在线示例。

关于javascript - 如何从Java通用网页中获取Favicon的URL? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10282939/

10-11 12:55