问题
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?
回答1:
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/
回答2:
Basically it gives you the ability to spit out one URL and have it use whatever protocol is currently being used.
Facebook probably uses the same HTML code regardless of whether the user is on HTTP or HTTPS. It's a way to fully qualify the domain without specifying the protocol.
回答3:
It's another type of relative URL, it uses the same protocol that the page is on.
来源:https://stackoverflow.com/questions/7693598/using-instead-of-protocol