Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

javascript - Get website's favicon with JS

I am wondering if it is possible to get a website's favicon by an URL with JavaScript.

For example I have an URL http://www.bbc.co.uk/ and I would like to get path to favicon described in <link rel="icon" .../> meta tag - http://www.bbc.co.uk/favicon.ico.

I have many URLs so that should not load every page and search for link tag I think.

Any ideas ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are 2 working options, I tested over 100 urls and got different results which each option. Please note, this solution is not JS, but JS may not be necessary.

<!-- Free --> 
<img height="16" width="16" src='http://www.google.com/s2/favicons?domain=www.edocuments.co.uk' />
<!-- Paid -->
<img height="16" width="16" src='http://grabicon.com/edocuments.co.uk' />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...