有一个网页
https://www.dataroma.com/m/holdings.php?m=BRK
里面有这样的表述
<a href="/m/hist/hist.php?f=BRK&s=AAPL" title="Holding/activity history">≡</a>
请问,这个链接的最终指向为何是
https://www.dataroma.com/m/hist/hist.php?f=BRK&s=AAPL
有一个网页
https://www.dataroma.com/m/holdings.php?m=BRK
里面有这样的表述
<a href="/m/hist/hist.php?f=BRK&s=AAPL" title="Holding/activity history">≡</a>
请问,这个链接的最终指向为何是
https://www.dataroma.com/m/hist/hist.php?f=BRK&s=AAPL
这个链接的最终指向是 https://www.dataroma.com/m/hist/hist.php?f=BRK&s=AAPL
,是因为这是在 <a>
标签的 href
属性中指定的链接。当用户点击这个链接时,浏览器会导航到这个 href
属性所指定的 URL。
在这个例子中,href="/m/hist/hist.php?f=BRK&s=AAPL"
是一个相对路径,它相对于当前页面的 URL (https://www.dataroma.com/m/holdings.php?m=BRK
) 来解析。浏览器会把这个相对路径添加到当前页面的 URL 的基础上,从而得到完整的 URL https://www.dataroma.com/m/hist/hist.php?f=BRK&s=AAPL
。
相对路径的解析规则是这样的:
/
开头,那么浏览器会在当前页面的域名后面加上这个路径。/
开头,那么浏览器会在当前页面的目录后面加上这个路径。在这个例子中,相对路径 "/m/hist/hist.php?f=BRK&s=AAPL"
开头是一个斜杠 /
,所以浏览器在 https://www.dataroma.com/m/holdings.php?m=BRK
的域名后面添加了这个路径,得到了完整的 URL https://www.dataroma.com/m/hist/hist.php?f=BRK&s=AAPL
。
2 回答1.4k 阅读✓ 已解决
2 回答846 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
1 回答847 阅读✓ 已解决
2 回答765 阅读
1 回答737 阅读✓ 已解决
2 回答1.1k 阅读
可以看看mdn

这种叫相对于源的 URL,源就是
location.origin
在你这个示例中就是https://www.dataroma.com