Html 链接到域根的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5553796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:48:04  来源:igfitidea点击:

What is the best way to link to domain root?

htmlhyperlink

提问by JKirchartz

I'm setting up links and not sure which is the best way to link to the domain root should I do

我正在设置链接,但不确定哪种是链接到域根目录的最佳方式

<a href="/">home</a>or <a href="http://example.com">home</a>?

<a href="/">home</a>或者<a href="http://example.com">home</a>

is there a cooler way that I'm unaware of?

有没有我不知道的更酷的方式?

回答by Brian Hicks

Unless you have a specific reason you want to always use HTTP, use <a href="/">text</a>. You'll run into problems with SSL otherwise.

除非您有特定原因想要始终使用 HTTP,否则请使用<a href="/">text</a>. 否则,您会遇到 SSL 问题。

There is a cooler way to do it if you're loading scripts, and that is to load cross domain scripts in a protocol-neutral way, as such:

如果您正在加载脚本,则有一种更酷的方法可以做到,那就是以协议中立的方式加载跨域脚本,例如:

<script src="//example-cdn.com/scripts/jquery-latest-min.js"></script>

That way you avoid the HTTP mixed content warnings in IE.

这样您就可以避免 IE 中的 HTTP 混合内容警告。

回答by Jan Zyka

the simpler /variant is portable across domains, might be considered as an advantage.

更简单的/变体可以跨域移植,这可能被认为是一个优势。

回答by Stephan

depends on the programming language you are using.. and the web-framework.. in plain html /would be your choice (portability)

取决于您使用的编程语言..和网络框架..纯html/将是您的选择(可移植性)