Home  >  Article  >  Web Front-end  >  Correlation analysis of hash and ico in js_javascript skills

Correlation analysis of hash and ico in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:15:41961browse

This article analyzes some relationships between hash and ico in js through examples. Share it with everyone for your reference. The details are as follows:

Recent testing revealed a bug, saying that the icos on some pages were not displayed, so we investigated the cause of this problem.

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 not to be displayed. The reason is that location.hash is set when the ico is not loaded, causing the ico not to be displayed.

location.hash is often used in projects for url positioning, such as "#job-manage" in http://h.liepin.com/#job-manage.

The solution is as follows (take the current project as an example and analyze the specific situation in detail):

Project points:

1. The page content is sent by clicking the menu to send an ajax request;

2. The displayed content when entering the page is the default click event of a certain menu;

3. Setting location.hash is through the click event of a certain menu.

There is a problem. When entering the page, the click event of the menu 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 design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn