Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Can not link to "id" in shortcuts

by Lady_Aleena (Priest)
on Jun 01, 2017 at 02:30 UTC ( [id://1191777]=monkdiscuss: print w/replies, xml ) Need Help??

I just tried to create a link to part of my scratchpad where I placed an id=. I tried [id://637756#laundry|my pad]. It did not munge. I just got [id://637756#laundry|my pad]. I would really like to link to tags with ids. For example, if I give an id to a section of my home node, I can link to just that section. Pretty please?

Update: It looks like I can not add ids to the html elements. They do not make it to display. 8(

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re: Can not link to "id" in shortcuts
by kcott (Archbishop) on Jun 01, 2017 at 06:52 UTC
Re: Can not link to "id" in shortcuts
by haukex (Archbishop) on Jun 01, 2017 at 05:17 UTC

      Using the name attribute on most elements is not the standard. The name attribute is to be used on button, fieldset, form, iframe, input, keygen, map, meta, object, output, param, select, and textarea. Using the name attribute on anything else will lead to poor HTML. The id attribute should be used, and is also what I am most used to using to create links to parts of an HTML document. You can look at the W3C list of attributes to double check me. I do not remember when it was good html to use name instead of id.

      Sorry for the impromptu lesson on HTML.

      No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
      Lady Aleena

        The markup on PerlMonks is not strict HTML; for instance, <code> tags are non-standard and square brackets are handled specially.

        For markup here, you'll need to use name attributes to create fragment identifiers to link to.

        I think the majority of browsers will accept name attribute values as fragment identifiers — I just successfully tested that with Firefox, Opera and Safari — so if you need to create links to sections here, from another site, you can do so like this:

        <a href="http://www.perlmonks.org/?node_id=43037#general">...</a>

        Important: Please do not use markup like that here! See "All Links Within PerlMonks Should Be Relative" for details.

        — Ken

        You've linked to the HTML 5 spec, which says that using the name attribute is a fallback when there is no such id in the document. PerlMonks is definitely not HTML 5 compliant, if you look at the source you'll see <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> (and even so it fails validation badly), so have a look at the HTML 4.01 spec. Plus, the Markup in the Monastery isn't even "real" HTML (<readmore>, <spoiler>, etc.). <a name="..."></a> has been the standard way to create an anchor as far back as HTML 2.0 HTML 1.0, so don't expect browsers to remove support for it anytime soon.

        Sorry for the impromptu lesson on HTML ;-P

        Update: I didn't see shmem's post before I posted.

        Update 2: <a name="..."> is additionally discussed in the HTML 5 spec in the section "Obsolete but conforming features".

        The name attribute is to be used on button, fieldset, form, iframe, input, keygen, map, meta, object, output, param , select, and textarea. Using the name attribute on anything else will lead to poor HTML.

        You forgot a which is the most common tag for which the name attribute is valid. <a></a> is anchor and it is used as <a href="$url">link text</a> and <a name="anchor_name">anchor in text</a> to mark an anchor in a page whose href would then be <a href="$url#anchor_name">target text</a>.

        So, For Lady_Aleena ([href://?node_id=535366#Lady_Aleena|For Lady_Aleena]) links to the copy of this node marked as <a name="Lady_Aleena">For Lady Aleena</a> on my scratchpad. This is described on What shortcuts can I use for linking to other information?.

        You cannot link to a id or to any tag for which the name attribute is valid and set, only to an anchor (<a name="foo">foo</a>).

        Sorry for the impromptu lesson on HTML and PerlMonks markup. :-D

        perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        D'oh! Me too, didn't know <a name=… is deprecated.

        Looks like the difference between HTML (up to 4) and HTML 5 is similiar to that between Perl and Perl 6 ;-P

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://1191777]
Approved by beech
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-24 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found