Forum Moderators: open

Message Too Old, No Replies

Link to #id on different webpage

Is it possible

         

darcbar

2:38 pm on Oct 26, 2009 (gmt 0)

10+ Year Member



Was just wondering if it was possible to create a link to certain section(#id) on a different webpage

When i use <a href="different_wbpage.html #id> it seems to work when i preview on my browser, but when i upload my site the links dont work ?

I have tried to search it but no luck, i believe you can only link to an #id on the same doc but just wanted to clarify.

thanks in advance

pageoneresults

2:48 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Was just wondering if it was possible to create a link to certain section(#id) on a different webpage?

Absolutely. You can even create links to other websites that utilize Fragment IDs.

Your using a relative path to reference the ID. To make it work cross site, use root relative paths like so...

<a href="/sub/different_wbpage.html#id">

When linking to third party documents with a Fragment ID.

<a href="http://www.example.com/sub/different_wbpage.html#id">

Be careful, Fragment IDs ARE case sensitive. I will normally cut and paste those to avoid retyping and introducing errors. ;)

[edited by: pageoneresults at 2:48 pm (utc) on Oct. 26, 2009]

swa66

2:48 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try:

<a href="different_wbpage.html#id">...</a>

tedster

2:52 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You definitely can link to a page fragment id in another document - even if it's on another website. Google has even started doing this recently in their search results.

What you report is a mystery to me, especially because you say it works locally for you. Does the link not even open the correct page? or just not jump to the correct spot?

pageoneresults

2:59 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think swa66 may have caught it if the code sample used is correct.

<a href="different_wbpage.html #id>

There's a space there between the Fragment and then we're also missing a closing quote. I was thinking maybe the OP put the space in there to prevent the system from doing something, and forgot the closing quote. ;)

piatkow

4:20 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If something works locally but not on the web I have usually found it to be due to case sensitivity. EG the fragment is #ID and the link is to #id

rocknbil

4:39 pm on Oct 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two cents thrown in, also works with dynamic pages and query strings:

some-script.php?s=1234#headId

Tip: don't use identifiers like "id" or "ID" - these may or may not conflict with the DOM if you use any Javascript.

Per P.1.R.'s thread [webmasterworld.com], one of the nuggets to be gleaned there and the various links in that topic opener is you don't need to use an anonymous anchor to do this (and shouldn't, is a waste, is less semantically correct:)

<a name="headId"></a>

Apply the identifier to a valid document element, it works just as well.

<h3 id="headId">Topic three</h3>

<p id="topicThree">Text of topic three</p>

It's the little things in developing pages than makes them better, smarter, easier to maintain.