为什么在HTML中使用href =“"//代替href ="http://? [英] Why using href="// instead of href="http:// in HTML?
问题描述
为什么在域名前使用<link href="//something.com/style.css" rel="stylesheet">
而不使用http://
或https://
?
Why using <link href="//something.com/style.css" rel="stylesheet">
instead of using http://
or https://
before the domain name?
如果我们使用href=//
,它会随着链接变化吗?就像在SSL模式下时一样,它将自动更改为https://
?
If we use href=//
does it changes with link? Like while in SSL mode will it automatically be changed to https://
?
推荐答案
是的,它将使用当前协议.
Yes, it will use the current protocol.
即如果当前页面为https
,它将使用https
访问href
.
i.e. if the current page is https
it will access the href
using https
.
如果为http
,则可以通过普通的http
访问该链接.
If http
then the link is accessed over plain http
.
如果托管页面为https
,它将防止浏览器警告,并且比普通的http
链接更加安全.
This will prevent browser warnings if the hosting page is https
and will be more secure than a plain http
link.
这篇关于为什么在HTML中使用href =“"//代替href ="http://?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!