如何检索“favicon.ico”当网站重定向 HTTP 请求时使用 AJAX 处理图像?
我正在使用 Ruby on Rails v3.0.9 和 jQuery 1.6。 我正在使用 JavaScript 函数(请参阅接受的答案),以便从某些网站检索 favicon.ico
图标图像。
正如您所看到的,除了 http://www.gmail.com
链接之外,所有工作都正常,我收到了 301 Moved Permanently
HTTP 状态响应。
我想改进 此 JavaScript 代码,以便遵循重定向,然后尝试在“重定向”URL 上查找 favicon.ico
图标图像。 如何改进该代码以便正确检索网站图标图像?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 JavaScript 没有任何问题。如果您尝试在浏览器中访问 favicon.ico,您会发现它甚至不会为您提供图标。 301 重定向指向 http://mail.google.com/mail/,这只会是 G-Mail 收件箱。该位置没有图像。这是
curl -i
的结果。G-邮件只是试图将人们带到他们的收件箱,因为那里什么也没有。 G-Mail 的 favicon.ico 的实际位置是 https://mail.google。 com/mail/images/2/mail_icon_32.png,它是通过 HTML 源中的
meta
标记设置的。来自 G-Mail 的来源:您可以在此处阅读更多相关信息。
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
.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:You can read more about that here.