html link
July 12, 2005 2:23 AM Subscribe
How do you create a link to the middle of the page?
I have searched on google and read some html tutorials. It seems like the answers they give me, and I am horrible with written directions, is that the page itself has to have a name anchor before I use it in the "a href" tag. But I want to create a link that jumps to a particular section in page that's not mine. Those don't usually come with a "name" anchor. How can I create a link to a section then?
I'm sorry if this isn't very clear. I don't even know the terminology of what exactly it is though I know what I want to do. Also sorry for such a stupid question *blushing*.
I have searched on google and read some html tutorials. It seems like the answers they give me, and I am horrible with written directions, is that the page itself has to have a name anchor before I use it in the "a href" tag. But I want to create a link that jumps to a particular section in page that's not mine. Those don't usually come with a "name" anchor. How can I create a link to a section then?
I'm sorry if this isn't very clear. I don't even know the terminology of what exactly it is though I know what I want to do. Also sorry for such a stupid question *blushing*.
If there's not a NAME tag in the page you're linking to, you can't. Sorry.
That said, many sites do have NAME tags in sensible places so it is definitely worth viewing the source HTML of the target site to find out if they do.
posted by handee at 2:40 AM on July 12, 2005
That said, many sites do have NAME tags in sensible places so it is definitely worth viewing the source HTML of the target site to find out if they do.
posted by handee at 2:40 AM on July 12, 2005
Best answer: In modern browsers anchors also apply to elements with
Therefore a link like
would take you to the anchor if it looked like this
or if it looked like this (swapped
But as any element can have an
or
or any other element with an
Of course, that means you need to look at the source code of the destination page and look for the nearest appropriate element with an
I don't think there is a sure-fire solution.
posted by NinjaPirate at 3:24 AM on July 12, 2005
id
attributes.Therefore a link like
<a href="#the_anchor">Go to the_anchor</a>
would take you to the anchor if it looked like this
<a name="the_anchor"></a>
or if it looked like this (swapped
name
for id
)<a id="the_anchor"></a>
But as any element can have an
id
attribute, the above examples are also functionally equivalent to<table id="the_anchor">[some content]</table>
or
<p id="the_anchor">[some content]</p>
or any other element with an
id
.Of course, that means you need to look at the source code of the destination page and look for the nearest appropriate element with an
id
attribute and even then you may not find a good fit.I don't think there is a sure-fire solution.
posted by NinjaPirate at 3:24 AM on July 12, 2005
Wow, thanks NinjaPirate! I thought I knew everything about HTML, but you just taught me something. I had no idea ANY id could be used as an anchor.
posted by lynda at 4:17 AM on July 12, 2005
posted by lynda at 4:17 AM on July 12, 2005
lynda: as of HTML 4.01/XHTML 1.0 'name' is deprecated in favor of 'id', except on form elements. So in HTML 4.01 Strict, XHTML 1.0 Strict and XHTML 1.1 it's illegal to use a 'name' attribute anywhere besides a form element.
posted by ubernostrum at 4:26 AM on July 12, 2005
posted by ubernostrum at 4:26 AM on July 12, 2005
Go here and insert the URL of your page. This tool will generate "Purple numbers" for the document, i.e. anchors for every paragraph on the page.
Um, right now the service seems to be down, but it's the only solution to your problem that I can think of. I'll (try to) contact the maintainer and see if it's only a temporary glitch.
posted by mumble at 4:39 AM on July 12, 2005
Um, right now the service seems to be down, but it's the only solution to your problem that I can think of. I'll (try to) contact the maintainer and see if it's only a temporary glitch.
posted by mumble at 4:39 AM on July 12, 2005
Best answer: Oops, forgot. If you'd like to check for anchors in an HTML document, the named anchors bookmarklet will do this for you without your having to peruse the source code of the page. Rather useful.
posted by mumble at 4:48 AM on July 12, 2005
posted by mumble at 4:48 AM on July 12, 2005
ubernostrum - that's not entirely true.
posted by NinjaPirate at 4:49 AM on July 12, 2005
name
was an HTML4 attribute and is entirely legal in 4.01 (for certain elements). It's deprecated in XHTML1.0; however, that doesn't mean it's illegal.posted by NinjaPirate at 4:49 AM on July 12, 2005
Here's a thingy I just knocked together from some old code that does what mumbles' link does, except more crudely.
posted by cillit bang at 4:52 AM on July 12, 2005
posted by cillit bang at 4:52 AM on July 12, 2005
NinjaPirate, the link you provided says "XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above." It appears the name attribute only exists so that people can use it as a duplicate of id for compatibility purposes.
posted by grouse at 4:53 AM on July 12, 2005
posted by grouse at 4:53 AM on July 12, 2005
um.... yes.. ? I didn't get the point.
What did I do wrong?
And sorry for the derail, state fxn
posted by NinjaPirate at 5:18 AM on July 12, 2005
What did I do wrong?
And sorry for the derail, state fxn
posted by NinjaPirate at 5:18 AM on July 12, 2005
Strictly speaking you are right, the name attribute is not prohibited. However, it is illegal to use it to define a fragment identifier and to not use id at the same time. In fact a conforming user agent must not recognize name attributes as fragment identifiers under certain circumstances.
I read your post to say that you have the choice of using id or name in XHTML 1.0 but name is deprecated. In reality, you have the choice of using either id or id+name, but name alone is not allowed.
posted by grouse at 5:54 AM on July 12, 2005
I read your post to say that you have the choice of using id or name in XHTML 1.0 but name is deprecated. In reality, you have the choice of using either id or id+name, but name alone is not allowed.
posted by grouse at 5:54 AM on July 12, 2005
Ah, I see. No, I was just saying that
</derail>
posted by NinjaPirate at 6:14 AM on July 12, 2005
name
wasn't yet outlawed.</derail>
posted by NinjaPirate at 6:14 AM on July 12, 2005
Does this work in a Mefi context? I've often wondered how people link to other people's comments in the same/another thread rather than just to the whole thread.
posted by penguin pie at 8:40 AM on July 12, 2005
posted by penguin pie at 8:40 AM on July 12, 2005
Best answer: In a MeFi context the thing to link to is the timestamp by the posting. For example, in yours it says 8:40 AM and if you right-click it and copy link location you get this:
http://ask.metafilter.com/mefi/21068#341446
If you want to link within the same thread you can either do that full paste of just use the #341446 - anything you leave off the left hand side is assumed to be the same as the current page.
So /this/thing would be ask.metafilter.com/this/thing in this context and #341446 would be http://ask.metafilter.com/mefi/21068#341446
posted by phearlez at 8:48 AM on July 12, 2005
http://ask.metafilter.com/mefi/21068#341446
If you want to link within the same thread you can either do that full paste of just use the #341446 - anything you leave off the left hand side is assumed to be the same as the current page.
So /this/thing would be ask.metafilter.com/this/thing in this context and #341446 would be http://ask.metafilter.com/mefi/21068#341446
posted by phearlez at 8:48 AM on July 12, 2005
Response by poster: Thank you so much Ninjypirate and mumble! And don't worry about the derail, I didn't know what you were talking about anyway, but I'm sure someone will appreciate the clarification. =)
On preview: Phearlez. You beat me to it! I was proud to have figured that out myself yesterday. Ah well.
posted by state fxn at 9:02 AM on July 12, 2005
On preview: Phearlez. You beat me to it! I was proud to have figured that out myself yesterday. Ah well.
posted by state fxn at 9:02 AM on July 12, 2005
NinjaPirate: I said "except on form elements".
posted by ubernostrum at 1:57 AM on July 15, 2005
posted by ubernostrum at 1:57 AM on July 15, 2005
This thread is closed to new comments.
(Though I guess there might be a way to do it with javascript or something)
posted by cillit bang at 2:39 AM on July 12, 2005