使用//而不是协议:// [英] using // instead of protocol://

查看:159
本文介绍了使用//而不是协议://的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

用< script src =""”> ;? 替换//是否有效?

绝对URL省略协议(方案),以保留当前页面的一个

在Javascript中使用//www.example.com是否自动选择http / https协议


我正在查看来自Facebook的一些示例代码,我看到:

 < script src =// connect.facebook.net/en_US/all.js\"> ;</script> 

它们使用 // 而不是 http:// - 这是我还不知道的 h2_lin>解决方案

它被称为协议相对URL。与以/开头的URL相对于当前域的根相似,以//开头的URL将链接到指定的主机和路径,但使用当前页面加载的任何协议。



在维基媒体博客中有一个很好的描述,以及它们为什么很有用:

http://blog.wikimedia.org/2011/07/ 19 / protocol-relative-urls-enabled-on-test-wikipedia-org /


Possible Duplicate:
Is it valid to replace with // in a <script src=“…”>?
Absolute URLs omitting the protocol (scheme) in order to preserve the one of the current page
Does using //www.example.com in Javascript chose http/https protocol automatically

I'm looking at some sample code from facebook and I see:

<script src="//connect.facebook.net/en_US/all.js"></script>

they use // instead of http:// -- is this something fancy that I don't know about yet?

解决方案

It's called a "protocol-relative URL". Similar to how a url starting with "/" is relative to the root of the current domain, a URL starting with "//" will link to the specified host and path, but using whatever protocol the current page was loaded using.

There's a nice description of them, and why they're useful, on the Wikimedia blog:

http://blog.wikimedia.org/2011/07/19/protocol-relative-urls-enabled-on-test-wikipedia-org/

这篇关于使用//而不是协议://的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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