HTML <a> 本地链接,target="_blank" 不起作用

问题描述 投票:0回答:3

我有这个问题:当我设置“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>

“目标”属性起作用。

两者有什么区别??

html
3个回答
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="~/" />

在标题标签之后,因此您指向根目录,然后您可以使用您拥有的内容。

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

0
投票

我也有同样的问题。链接会打开,只是不在新窗口中打开。绝对链接在新窗口中打开,但相对链接在同一窗口中打开。我已经测试了几次,唯一改变的是添加 https://www.domainnamehere.com/ ...

© www.soinside.com 2019 - 2024. All rights reserved.