假设有一个网站位于http://example.com/myWebsite/
。
我希望我的绝对路径指向myWebsite
目录。
我知道可以使用base
标记来处理相对链接,但我希望保留相对链接的默认行为。
在头部是否有什么有用的东西可以指定?
<!DOCTYPE html>
<html>
<head>
<base href="http://example.com/myWebsite/" target="_blank">
</head>
<body>
<p><img src="stickman.gif" width="24" height="39" alt="Stickman"> -
Notice that we have only specified a relative address for the image.
Since we have specified a base URL in the head section, the browser will
look for the image at "http://example.com/myWebsite/stickman.gif".
</p>
</body>
</html>
。
http://example.com/myWebsite/directory/index.html
页面上,任何类似 ./image.png
的链接都会被翻译成 http://example.com/myWebsite/image.png
而不是 http://example.com/myWebsite/directory/image.png
。 - Apolo
https://stackoverflow.com
或https://www.google.com
这样的URL相对于你自己的域名。如果你希望保持相对URL的默认行为,只需不使用基本元素 - 它并非必需。 - BoltClock