Link to a section of a webpage - html

I want to make a link that when clicked, sends you to a certain line on the page (or another page). I know this is possible, but how do I do it?

your jump link looks like this
jump link
Then make
<div id="div_id"></div>
the jump link will take you to that div

Hashtags at the end of the URL bring a visitor to the element with the ID: e.g.
http://stackoverflow.com/questions/8424785/link-to-a-section-of-a-webpage#answers
Would bring you to where the DIV with the ID 'answers' begins. Also, you can use the name attribute in anchor tags, to create the same effect.
Resource

The fragment identifier (also known as: Fragment IDs, Anchor Identifiers, Named Anchors) introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document.
Link to fragment identifier
Syntax for URIs also allows an optional query part introduced by a question mark ?. In URIs with a query and a fragment the fragment follows the query.
Link to fragment with a query
When a Web browser requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent (Web browser) processes the resource according to the document type and fragment value.
Named Anchors <a name="fragment"> are deprecated in XHTML 1.0, the ID attribute is the suggested replacement. <div id="fragment"></div>

If you are a user and not a site developer, you can do it as follows:
https://example.com/index.html#:~:text=foo

Simple:
Use <section>.
and use Visit the Useful Tips Section
w3school.com/html_links

Related

URL to an unnamed part of a web page

I'd like to refer to a specific part of a web page which I am not the author of, and which is not tagged with the NAME attribute. The specification of the part I have in mind could be made, e.g., as the location a certain word appears, and which could be manually reached via a FIND operation. I imagine something like
http://somesite.com#search-for:foo-bar
Is there some feature in HTML allowing for this?
No.
You can only link to elements with an id and a elements with a name.

How to point to an anchor when the fragment identifier is already used in the URL?

I have a page (over which I have no control) with an URL similar to
https://example.com/#group:1106/about:Bxk9H9jJQOm-pYkmpZVjhA
Within this page, there is an element
<h1 id="content-H1-59520">Introduction</h1>
Fragment identifiers (#) can be used to point to a specific id on a page:
In URIs for MIME text/html pages such as
http://www.example.org/foo.html#bar the fragment refers to the element
with id="bar".
My question: taken into account that the fragment identifier is already used in the bare URL, how should I modify it to have it pointing to the H1 element above?
On a hunch I tried https://example.com/#group:1106/about:Bxk9H9jJQOm-pYkmpZVjhA#content-H1-59520 but it does not work.
The fragment identifier component is indicated by the first # and terminated by the end of the URL. The URL you tested is invalid, because the fragment identifier component may not contain a #.
The URL has to be:
https://example.com/#content-H1-59520
If a JavaScript-based site requires the fragment identifier to represent application states, it conflicts with the browser feature to jump to an ID.
You could either switch to a different URI design (that doesn’t require the fragment identifier component), or maybe you could rebuild the jump feature in JavaScript (e.g., appending the anchor ID to the fragment, delimited by #).

Making a direcly link on the page

I want to do this:
this is the list
- Option 1 how to keep warm
- Option 2 how to keep cold
way down on the doc. comes the answer
here is the answer for keeping you warm (this is were I want to go to. option 1)
You're looking for named anchor/named target/bookmark anchor links. Their format is essentially the same as that of normal anchors, however instead of pointing to a page, you point to the ID of the element you want to jump to.
For example:
Option 1 how to keep warm
Then further on down the page:
<h4 id="option1">here is the answer for keeping you warm</h4>
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a, specifically the section that says:
href This is the single required attribute for anchors defining a hypertext source link. It indicates the link target, either a URL or a
URL fragment. A URL fragment is a name preceded by a hash mark (#),
which specifies an internal target location (an ID) within the current
document. URLs are not restricted to Web (HTTP)-based documents. URLs
might use any protocol supported by the browser. For example, file,
ftp, and mailto work in most user agents.

what is the # symbol in the url

I went to some photo sharing site, so when I click the photo, it direct me to a url like
www.example.com/photoshare.php?photoid=1234445
. and when I click the other photo in this page the url become
www.example.com/photoshare.php?photoid=1234445#3338901
and if I click other photos in the same page, the only the number behind # changes. Same as the pretty photo like
www.example.com/photoshare.php?album=holiday#!prettyPhoto[gallery2]/2/
.I assume they used ajax because the whole page seems not loaded, but the url is changed.
The portion of a URL (including and) following the # is the fragment identifier. It is special from the rest of the URL. The key to remember is "client-side only" (of course, a client could choose to send it to the server ... just not as a fragment identifier):
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server — of course the server typically helps to 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 the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.
This can be used to navigate to "anchor" links, like: http://en.wikipedia.org/wiki/Fragment_identifier#Basics (note how it goes the "Basics" section).
While this used to just go to "anchors" in the past, it is now used to store navigatable state in many JavaScript-powered sites -- gmail makes heavy use of it, for instance. And, as is the case here, there is some "photoshare" JavaScript that also makes use of the fragment identifier for state/navigation.
Thus, as suspected, the JavaScript "captures" the fragment (sometimes called "hash") changing and performs AJAX (or other background task) to update the page. The page itself is not reloaded when the fragment changes because the URL still refers to the same server resource (the part of the URL before the fragment identifier).
Newer browsers support the onhashchange event but monitoring has been supported for a long time by various polling techniques.
Happy coding.
It's called the fragment identifier. It identifies a "part" of the page. If there is an element with a name or id attribute equal to the fragment text, it will cause the page to scroll to that element. They're also used by rich JavaScript apps to refer to different parts of the app even though all the functionality is located on a single HTML page.
Lately, you'll often see fragments that start with "#!". Although these are still technically just fragments that start with the ! character, that format was specified by Google to help make these AJAXy pseudo-pages crawlable.
The '#' symbol in the context of a url (and other things) is called a hash, what comes after the hash is called a fragment. Using JavaScript you can access the fragment and use its contents.
For example most browsers implement a 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 would print 'somethingelse' to the console. If we didn't use substr to remove the first character, it frag would be: '#somethingelse'.
Also, when you navigate to a URL with a hashtag, the browser will try and scroll down to an element which has an id corresponding to the fragment.
http://en.wikipedia.org/wiki/Fragment_identifier
It is the name attribute of an anchor URL: http://www.w3schools.com/HTML/html_links.asp
It is used to make a bookmark within an HTML page (and not to be confused with bookmarks in toolbars, etc.).
In your example, if you bookmarked the page with the # symbol in the URL, when you visit that bookmark again it will display the last image that you viewed, most likely an image that has the id of 3338901.
hey i used sumthing like this .... simple but useful
location.href = data.url.replace(/%2523/, '%23');
where data.url is my original url . It substitutes the # in my url

Why is the # convention used in empty anchor tag hrefs?

I understand that it's a good idea not to leave empty anchor tags. In jQuery and other syntaxes I've noticed everyone typically uses a # to fill the gap (<a href='#'>anchor text</a>). Is this character any better or worse than filling it with anything else? (e.g. <a href='$'>anchor text</a>). I have no reason to want to do this, but seemingly no reason aside from convention to do it the other way either. Why is the # convention used in empty anchor tag hrefs?
This is because the # character in a URL references the local page.
It is used for named anchors (or any ID) within a page, so a link can jump directly to that area.
Wikipedia calls it the fragment identifier and has this to say:
The fragment identifier, if present, specifies a part or a position within the overall resource or document. When used with HTTP, it usually specifies a section or location within the page, and the browser may scroll to display that part of the page.
As a practical example - this link to wikipedia has a fragment identifier (always at the end of the URL):
http://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax
In the page, there is a <span id="Syntax" ... tag, and the browser jumps directly to it.
This way, if the user has disabled javascript, actually following the link to "http://mysite.com/#" will not have any negative consequences.
For example, these links still work, since # specifies a location on the current page:
http://www.stackoverflow.com#
http://www.stackoverflow.com/#
while these don't:
http://www.stackoverflow.com$
http://www.stackoverflow.com/$
The link denoted by <a href= points to somewhere else. This somewhere could be on the other side of the world (absolute URL), or locally on the same domain/path (relative URL). Just leaving it empty refers to the very document itself.
The # is the character used to separate an anchor from the rest of the URL. Browers don't even send it to the server, but use it to vertically scroll to the position in the page marked with this anchor (using <a name="foo"></a>).
So basically, <a href="#"> instructs the browser to stay on the same page. It is usually used together with JavaScript - hooking into onClick events - so that the JavaScript does something useful, then return false to prevent the browser from actually following the link. But if he would (e.g. if JavaScript is disabled, or return false is ommitted) then it would not leave the current site, usually not even reloading it.
So #is used not as a random char, but because that's actually the char specified for the purpose of denoting an anchor in a link - it just happens that in your case you neither need the actual link (to another page) nor the anchor, but just a clickable element.
it's mostly old school way of preventing the click action to trigger a page reload.
If you aren t using the href attribute just leave it empty, or even better if you can target some fallback URL for people with JS disabled