为什么在HTML中使用href =“"//代替href ="http://? [英] Why using href="// instead of href="http:// in HTML?

查看:228
本文介绍了为什么在HTML中使用href =“"//代替href ="http://?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在域名前使用<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆