Firefox have a weird bug related to the change of location.hash value, when you change this value the favicon disappears, I've spent a whole
day searching how to fix this
, the solution is simple all you have to do is to remove the favicon link then set it again after any change of the
location.hash value
.
Here’s the jQuery function from http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/:
function setFavicon() { var link = $('link[type=image/x-icon]').remove().attr("href"); $('<link href="'+ link +'" rel="shortcut icon" type="image/x-icon" />').appendTo('head'); }
and add setFavicon(); after any location.hash=url;
Based on the second comment bellow 1- You should use quotes in the attribute selector like follow to make it work with new version of JQuery: $('link[type="image/x-icon"]').remove().attr("href"); 2- It's better to test on the rel attribute instead of testing on the type attribute because firstly a Favicon is not necessarily of type ico and secondly if we follow the HTML standard (http://en.wikipedia.org/wiki/Favicon) a favicon is known by the rel="icon" attribute value: $('link[rel*="icon"]').remove().attr("href");
2 comments:
Saved my day. Thanks.
Two remarks if i may:
1- You should use quotes in the attribute selector like follow to make it work with new version of JQuery:
$('link[type="image/x-icon"]').remove().attr("href");
2- It's better to test on the rel attribute instead of testing on the type attribute because firstly a Favicon is not necessarily of type ico
and secondly if we follow the HTML standard (http://en.wikipedia.org/wiki/Favicon) a favicon is known by the rel="icon" attribute value:
$('link[rel*="icon"]').remove().attr("href");
N.B: FWIW I'm not sure if this will be enough if you want to have a solution that work everywhere :)
Post a Comment