1. Include#What is the URL of?

A URL that contains the # symbol is a Fragment URL. # specifies a location in the web page.

name
print
<a>
<a name="print"></a>



id
print
<a>
<a id="print"></a>


2. Http requests are not included#

# only applies to browsers, it does not affect the server side. So HTTP requests don’t include #. Visit the website below

http://www.example.com/index.html#print
Copy the code

The actual request made by the browser

    GET /index.html HTTP/1.1
    Host: www.example.com
Copy the code

3. #All characters that follow are treated as location identifiers by the browser.

When the form is submitted, if the submission character contains the # character, the following parameters will be truncated.

4. Modify#Does not cause the page to reload, but changes the browser’s history

location.href += '#caper'; // The page will not refreshCopy the code

The browser scrolls to the new location, but the entire page is not reload.

However, it changes the browser record so that we can return to the original location by clicking the button on the previous page of the browser. This feature is very useful for single page applications.

5. Javascript can passwindow.location.hashTo read or change#

6. Google’s Web spider ignores the # by default

The Google Web Spider is responsible for crawling the content of web pages, as well as links within them, and they become part of Google’s search index. The Web spider crawls and analyzes HTML, but since it is not a browser program and does not have a javascript engine, the javascript used to load display content on the page is not executed. Therefore, the character after # is ignored by the web spider and only grabs the content before #, for example:

http://www.cnblogs.com/#casper
http://www.cnblogs.com/#chyingp
Copy the code

This is bad for both the developer, whose hard-earned content (apps) is less accessible, and the search engine, which loses the opportunity to further enrich its content index, especially with the increasing number of Ajax applications.

Solution Hash Bang

Just change # to #! When a web spider encounters #! Will automatically change the #! Identifier is converted to an argument of the form _escaped_fragment_=identifier. But:

  • will#to! #Tell the web spider: We support this solution:hash bang
  • Accordingly, our application also needs to have the corresponding support capability for the web spider beltescaped_fragment=casperYou need to be able to provide the corresponding web page content

7. Onhashchange event

This is a new HTML 5 event that is triggered when the # value changes. Internet Explorer 8+, Firefox 3.6+, Chrome 5+, and Safari 4.0+ support this event.

It can be used in three ways:

window.onhashchange = func;

<body onhashchange="func();">

window.addEventListener("hashchange", func, false);
Copy the code

Reference documentation

  1. 6 Things You Should Know About Fragment URLs
  2. Well Numbers of urls