This article analyzes some relationships between hash and ico in js. Share it for your reference. The details are as follows:
A recent test raised a bug, saying that the ICO in some pages does not display, so the cause of this problem was investigated.
First, make sure that the link in the page has introduced favicon.ico. After checking, it was found that the location.hash in js caused the ico to not display. The reason is that location.hash is set when the ico is not loaded, which causes the ico to not display.
location.hash is often used in projects and is used for url positioning, such as "#job-manage" in http://h.liepin.com/#job-manage.
The solution is as follows (taking the current project as an example, and the specific situation is analyzed):
Project points:
1. The page content is sent by clicking menu to send ajax request;
2. The displayed content on the page is the default click event of a menu;
3. Set location.hash is a click event through a menu.
This has a problem. When entering the page, the menu click event is executed, so location.hash is set.
You can do this by setting a variable to ensure that location.hash is not set when you first enter the page.
$(function(){ $('.menu a').click(function(event,hashBoolean){ var that = $(this); $.ajax({ url:'', type:'GET', data:{}, cache:false, dataType:'json', success:function(data){ if(data.flag == 1){ if(!hashBoolean) location.hash = ['id',that.attr('data-id')].join('='); } } }); $('.menu a').eq(0).trigger('click',[true]);});I hope this article will be helpful to everyone's JavaScript programming.