最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

permalinks - why does anchor name add a slash to url?

programmeradmin2浏览0评论

I am trying to do what should be some the most basic html, but it's not working for me. Here is my code:

<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>

I want to use the anchor name to fly down the contact page to the correct section.

When I use a link within the contact page like this:

<a href="#rocket">click here</a>

it works fine. But i want to come from another page and then fly down. So I am using this:

<a href="">click here</a>

but it seems to add a slash after contact and redirect to , which means that it stays at the top of the contact page instead of flying down.

Does anyone know why this is happening? If you could point me in the right direction, I'd be grateful.

Thanks,

Yukon

ps, i have read all similar questions on this site, but they don't help me.

I am trying to do what should be some the most basic html, but it's not working for me. Here is my code:

<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>

I want to use the anchor name to fly down the contact page to the correct section.

When I use a link within the contact page like this:

<a href="#rocket">click here</a>

it works fine. But i want to come from another page and then fly down. So I am using this:

<a href="http://mysite/contact#rocket">click here</a>

but it seems to add a slash after contact and redirect to http://mysite/contact/#rocket, which means that it stays at the top of the contact page instead of flying down.

Does anyone know why this is happening? If you could point me in the right direction, I'd be grateful.

Thanks,

Yukon

ps, i have read all similar questions on this site, but they don't help me.

Share Improve this question asked May 8, 2013 at 21:58 Yukon CorneliusYukon Cornelius 411 gold badge1 silver badge2 bronze badges 3
  • 3 Is the anchor's href attribute really hardcoded (as HTML) like that, or is that the expected output of something? – Johannes P. Commented May 8, 2013 at 22:17
  • 1 Question resolved: wordpress/support/topic/anchor-name-adds-a-slash?replies=6 – Andrew Bartel Commented May 8, 2013 at 23:28
  • thx again Andrew. In case anyone else is bashing their head against the wall with the same problem, the trailing slash causes all the trouble, so try mysite/contact/#rocket instead of mysite/contact/#rocket Probably a noob mistake, but i thought I'd share it. – Yukon Cornelius Commented May 9, 2013 at 0:48
Add a comment  | 

1 Answer 1

Reset to default 7

It is okay that the URL changes to http://mysite/contact/#rocket, but you should change the way you are defining your anchor on the target page.

Instead of using this method

<a name="rocket"></a>
<div>
<h3>The Title</h3>
<p>some text</p>
</div>

You should add an ID to the content you want to jump to like this:

<div id="rocket">
<h3>The Title</h3>
<p>some text</p>
</div>

This way your HTML markup is cleaner and there isn't an extra <a> element for the jump.

发布评论

评论列表(0)

  1. 暂无评论