I am trying to use internal page links for a page that is quite long.
When I do <a name="name">name</a> to give a reference to where the link should go.
Then at the top give call that link. <a href="#name">go to name</a>.
It takes me back to the main page when I click "go to name". The strange part is the URL for when it takes me back to the main page ends in /#name.

Anyone have any ideas? This normally works just fine for me in normal html. That is with using full html.

Comments

DriesK’s picture

That's because of the base tag. For example, this site has the following base tag in its head section:
<base href="http://drupal.org/" />
This means that all links will be relative to the base url, so <a href="#name"> will refer to http://drupal.org/#name.

A flexible way to deal with this, is to use the PHP code input format instead of HTML, and use Drupal's l-function like this:

print l('name', $_GET['q'].'#name');

The first 'name' is the text that will be displayed as a link.

Dave Cohen’s picture

If the page you're linking within is the result of a get, you may be better off with something like:

<a href="/<?=$_SERVER['REQUEST_URI']?>#name">...</a>

That seems to be working for me, when the original URL has get variables appended to it.

In my case, I'm converting some pages I had written long ago to work within drupal. Its possible noone using drupal from scratch would run into this.

Bèr Kessels’s picture

DriesK's example has all the get variable too. On top of that, it will generate nicer drupal-specific uls.

---
if you dont like the choices being made for you, you should start making your own.
---
[Bèr Kessels | Drupal services www.webschuur.com]

Wesley Tanaka’s picture

There's a patch available to remove the base tag from drupal generated pages, which would allow you to create links like '#name' when you don't want to or can't use PHP code.

If that feature would be useful for you, consider adding a comment to that effect on http://drupal.org/node/13148

Treehouse

Ander5’s picture

I just devised a simple way to do this:

$node = 9; // node id here until I find a more graceful way to obtain it.
echo "<a name=\"top\"></a>";

echo "<a href=\"node/$node#top\">Top</a>";

I hope that helps.