【问题标题】:Can I use relative <a href=#foo> and go to a named anchor on the current page when when <base> is being used?当使用 <base> 时,我可以使用相对 <a href=#foo> 并转到当前页面上的命名锚点吗?
【发布时间】:2021-06-25 23:29:04
【问题描述】:

如果我有一个页面www.example1.com/foo/test.html如下:

<head>
<base href=http://www.example2.com/>
</head>
<body>
<a href=#foo>foo</a>
...
<a name=foo />
</body>

然后,当我单击“foo”时,它会将我带到http://www.example2.com/#foo,而不是当前页面的 foo。我想这是有道理的,但是当&lt;base&gt; 指向其他地方时,有没有办法进行页面本地命名锚点跳转?

请注意,test.html 是动态命名的,因此 href=...#foo 中的绝对路径不是一个选项。一些 JS 可能是,但 strait html 会是首选。

【问题讨论】:

    标签: html tags href anchor


    【解决方案1】:

    这是预期的行为,文档说所有相对链接都与包含锚点有关:

    另见:

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 2012-11-15
      • 1970-01-01
      • 2019-10-30
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多