Backo
Backo

Reputation: 18871

How to retrieve a 'favicon.ico' image using AJAX when a web site redirects a HTTP request?

I am using Ruby on Rails v3.0.9 and jQuery 1.6. I am using a JavaScript function (see the accepted answer) so to retrieve the favicon.ico icon image from some web sites.

As you can see all works good except for the http://www.gmail.com link for which I get a 301 Moved Permanently HTTP status response.

enter image description here

I would like to improve this JavaScript code so to follow the redirection and then try to find the favicon.ico icon image on the "redirected" URL. How can I improve that code so to correctly retrieve the favicon image?

Upvotes: 0

Views: 1479

Answers (1)

vcsjones
vcsjones

Reputation: 141638

There is nothing wrong with your JavaScript. If you try going to the favicon.ico in a browser, you'll see that it won't even give you the icon. The 301 Redirect is pointing to http://mail.google.com/mail/, which would just be a G-Mail inbox. There is no image at this location. This was the result from curl -i.

HTTP/1.1 301 Moved Permanently

Location: http://mail.google.com/mail/

G-Mail is just trying to take the person to their inbox since there is nothing there. The actual location of G-Mail's favicon.ico is https://mail.google.com/mail/images/2/mail_icon_32.png, which is set via a meta tag in the HTML source. From G-Mail's source:

<link rel="icon" href="images/2/mail_icon_32.png" sizes="32x32"> 

You can read more about that here.

Upvotes: 2

Related Questions