开发者

jQuery to force all favicon.ico requests to the correct location?

开发者 https://www.devze.com 2022-12-10 20:47 出处:网络
I do not have server-side access. I\'m trying to present a custom favicon from a hosted wiki service that provides scripting and CSS access bu开发者_如何学运维t presents its own favicon to all its us

I do not have server-side access.

I'm trying to present a custom favicon from a hosted wiki service that provides scripting and CSS access bu开发者_如何学运维t presents its own favicon to all its users.

Is it possible to do something like this but with jQuery? If so, how?


jQuery is Javascript, which runs client-side once a page has been returned.

The request for the favicon is a pure HTTP request from browser to server, no page is loaded. You can only redirect requests like that using server-side techniques (such as the one you linked to).

There are a million ways you can do it server-side (.htaccess files, php redirects, etc.) but jQuery simply is not an option.


The most reliable way is to put /favicon.ico at the root of your site. But to point to another image you can use code like this, as featured at the Wikipedia favicon page:

<link rel="icon" type="image/x-icon" href="/somepath/image.ico" />
<link rel="SHORTCUT ICON" href="/somepath/image.ico" />

Adjust the path and type value to match the image type.

No jQuery, though I suppose you could write JavaScript to inject these tags into the <head> so browsers would see them, but it seems easier just to add the html <link> tags.


No. The search engine spiders mentioned as issues in that post will not load and execute your JavaScript code.

0

精彩评论

暂无评论...
验证码 换一张
取 消