Is it OK to use empty href on links with <base> tag

断了今生、忘了曾经 提交于 2019-12-12 13:40:42

问题


I set the base tag as such:

<base href="http://mnapoli.github.com/PHP-DI/">

Then I would like to create a link to http://mnapoli.github.com/PHP-DI/ in relative path.

I tried:

<a href="">link</a>

and it works in Chrome, but is this method standard and supposed to work on every browser?


回答1:


Although href="./" as suggested in Mike’s answer is better (easier to understand to anyone who reads the code), the answer to the question posed is that using an empty URL is standard and supposed to work on all browsers. According to STD 66, a relative URL with no characters (path-empty) is allowed, and by rules on relative URLs, it is resolved as the base URL.

This has nothing to do with folders or files; URLs are strings, and whether they get mapped to folders or files on a server is at the discretion of the server.




回答2:


I would do something like this:

<base href="http://mnapoli.github.com/PHP-DI/">

<a href="./">Home</a>


来源:https://stackoverflow.com/questions/13019985/is-it-ok-to-use-empty-href-on-links-with-base-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!