What is the # character in the url

I went to a photo sharing site, so when I click on a photo, it directs me to a URL, for example

www.example.com/photoshare.php?photoid=1234445

. and when I click another photo on this page, the URL becomes

www.example.com/photoshare.php?photoid=1234445#3338901

and if I click other photos on one page, only the number for # will change. Same as a beautiful photograph, for example

www.example.com/photoshare.php?album=holiday#!prettyPhoto[gallery2]/2/

. I assume they used ajax because the whole page does not seem to be loaded, but the url is changed.

+6
source share
5 answers

The portion of the URL (including and) following # is the fragment identifier . It is different from the rest of the URL. The key to remembering is only the "client side" (of course, the client can choose to send it to the server ... just not as a fragment identifier):

The fragment identifier works differently than the rest of the URI: it is processed exclusively on the client side without server participation . Of course, the server usually helps determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a web browser) requests a resource from a web server, the agent sends a URI to the server but does not send a fragment. . The agent expects the server to send the resource, and then the agent processes the resource according to the type of document and its value.

This can be used to navigate to anchor links, for example: http://en.wikipedia.org/wiki/Fragment_identifier#Basics (note how this happens in the Basics section).

While it was used to just go to the “bindings” in the past, it is now used to store navigation state on many JavaScript-enabled sites - for example, gmail uses it heavily. And, as in this case, there is some “photorating” JavaScript that also uses the fragment identifier for state / navigation.

Thus, as expected, JavaScript “captures” the snippet (sometimes called a “hash”) and performs AJAX (or another background task) to refresh the page. The page itself does not reload when the fragment changes, because the URL still refers to the same server resource (the part of the URL before the fragment identifier).

New browsers support the onhashchange event, but monitoring has been supported for a long time by various polling methods.

Happy coding.

+10
source

It is called a fragment identifier. It identifies the "part" of the page. If there is an element with the name or id attribute equal to the text of the fragment, it will make the page scroll to this element. They are also used by rich JavaScript applications to link to different parts of the application, although all the functionality is located on the same HTML page.

Recently, you will often see snippets starting with "#!". Although they are still technically just fragments starting with a symbol ! This format was specified by Google to make these AJAXy pseudo-pastes complete.

+4
source

This is the attribute name of the binding URL: http://www.w3schools.com/HTML/html_links.asp

It is used to create bookmarks inside an HTML page (and not to be confused with bookmarks in toolbars, etc.).

In your example, if you marked a page with the # symbol in the URL, when you visit this bookmark again, the last image you viewed will most likely be the image with ID 3338901.

+1
source

The symbol "#" in the context of a URL (and other things) is called a hash, which happens after the hash is called a fragment. Using JavaScript, you can access the fragment and use its contents.

For example, most browsers implement the onhashchange event, which fires when the hash changes. Using JavaScript, you can also access the hash from location.hash . For example with a url like http://something.com#somethingelse

 var frag = location.hash.substr(1); console.log(frag); 

This will print "somethingelse" on the console. If we did not use substr to remove the first character, it would be frag : '#somethingelse'.

In addition, when you navigate to the hashtag URL, the browser will try and scroll down to the element with the id corresponding to the fragment.

http://en.wikipedia.org/wiki/Fragment_identifier

+1
source

Hey, I used sumthing like this .... simple but useful

  location.href = data.url.replace(/%2523/, '%23'); 

where data.url is my source url. It replaces # in my url

0
source

Source: https://habr.com/ru/post/900167/


All Articles