首页 文章

HTML <a>本地链接,target =“_ blank”不起作用

提问于
浏览
0

我有这个问题:当我设置“href”属性时,相对URL如下:

<a href="/app/site/index.php" target=“_blank”>test</a>

它无法在新窗口或选项卡中打开链接文档,但是当我将“href”更改为绝对URL时,如:

<a href="http://www.ou-lee.com/app/site/index.php" target=“_blank”>test</a>

“目标”属性是有效的 .

两者之间的区别是什么?

2 回答

  • 0

    根据您提供的限制信息,这里只是猜测:

    如果包含该链接的html页面已经在 http://www.ou-lee.com/app/site/ 中,例如 http://www.ou-lee.com/app/site/somepage.php

    那么相对路径应该只是index.php: <a href="index.php" target=“_blank”>test</a>

    相对路径是相对于当前位置(文件夹),而不是相对于根域 .

    如果当前页面位于 http://www.ou-lee.com/somefolder/ 并且您想使用相对URL来获取 app/site/index.php ,则可以使此更清晰的另一个示例 . 首先你必须上升一级 ../ 然后你会去 app/site/index.php 所以你的整个 href 应该是: ../app/site/index.php

  • 0
    <a href="../app/site/index.php" target=“_blank”>test</a>
    

    在不知道你的文件夹结构的情况下,我只能假设它是上面的一步 .

    另一种方式是使用,

    <base href="~/" />
    

    在你的 Headers 标签之后,所以你指向root,然后你可以使用你拥有的 .

    <a href="/app/site/index.php" target=“_blank”>test</a>
    

相关问题