2019-07-31 10:58
浏览 57


I try to use the anchor tag with the include I have. On my Index.php I got a little "nav bar" with some anchor tags. I also included the file "text.php" in my code. This file is in the Folder "texte". The anchor tags should bring the user to the position in text.php but it only load 404 - page not found.

How I include the file:

<?php include 'texte/text.php'; ?>

I declare my "start-word" like this:

<a href=“texte/text.php#InfoAnker“>Informationen</a>

And my anchor like this:

<h2 id="InfoAnker"> Informationen </h2>

I also tried <a href=“#InfoAnker“>Informationen</a> because of the include but it came out the same result.

Any ideas?

图片转代码服务由CSDN问答提供 功能建议

我尝试将锚标记与我拥有的包含一起使用。 在我的Index.php上,我得到了一个带有一些锚标签的“导航栏”。 我还在我的代码中包含了“text.php”文件。 此文件位于文件夹“texte”中。 锚标记应该将用户带到text.php中的位置,但它只加载404 - 找不到页面。

我如何包含 file:

 &lt;?php include'texte / text.php';  ?&gt; 


 &lt; a href =  “texte / text.php#InfoAnker”&gt; Informationen&lt; / a&gt; 


  &lt; h2 id =“InfoAnker”&gt;  Informationen&lt; / h2&gt; 

我还尝试了&lt; a href =“#InfoAnker”&gt; Informationen&lt; / a&gt; ,因为 包括但它得出了相同的结果。


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongshi1102 2019-07-31 11:27

    If <h2 id="InfoAnker"> Informationen </h2> is generated somewhere within your page and sent to the browser, then an anchor link should work correctly as

    <a href="#InfoAnker">Informationen</a>

    One think I noticed from your example is that you should make sure you use " not for quote marks - these are not the same characters, and you must use the correct one.

    Clicking on an anchor link should not result in a 404 error, if it's correctly defined. Even if the anchor ID doesn't actually exist in the page, it still wouldn't give a 404 - the worst that would occur would be that nothing would happen.

    解决 无用
    打赏 举报
  • drymoeuka282427675 2019-07-31 11:38

    Additionally to what @ADyson said:

    Anchor links work on the browser side. The form #InfoAnker redirects to an anchor on the same page, while texte/text.php#InfoAnker redirects to another page. Again: on the browser side.

    But I see, you are using includes, which work on server side. Normally, you don't have the same path and file structure on server and client (if your server include is located outside of wwwroot for example, but also for hiding confidential data and your program structure). This is most likely the reason why you see the 404. So if you want to access the piece of text that was included in your script, your redirect must not have a url.

    But for this to work, you need to define the anchor itself, using <h2 id="InfoAnker"> Informationen</h2>, either in the include or in the file which includes text.php

    解决 无用
    打赏 举报

相关推荐 更多相似问题