2011-10-07 137 views
9

可能重复:
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//,而不是协议://

我期待在从Facebook一些示例代码,我看到:

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

他们使用//而不是http:// - 这是什么花式,我不知道呢?

+5

我发誓这是一个非常着名的极端投票问题的副本,但我明白如果你搜索并找不到原来的问题,因为我也不能。 – BoltClock

+1

这篇文章回答了这个问题http:// stackoverflow .com/questions/3583103/scheme-relative-urls,但是如果你不知道搜索* scheme的相对URL *,你不会找到它 –

+0

@BoltClock我知道你正在谈论的确切问题,但我也找不到它。 –

回答

2

基本上它可以让你吐出一个URL并使用任何目前正在使用的协议。

无论用户使用HTTP还是HTTPS,Facebook都可能使用相同的HTML代码。这是完全限定域而不指定协议的一种方式。

0

这是另一种类型的相对URL,它使用相同的协议,该协议的页面上。