Why does "//" instead of http or https before the actual link work?

Solution 1:

How something like // is handled by the browser will vary by browser. As the standard usage case is http:// and would work across all browsers without a problem.

That being said, the majority of browsers will attempt HTTP where possible since that is what the browsers are used most often for. It is also the safest choice, HTTP traffic is sandboxed as best as possible by the browser and should be more secure than assuming the address is local.

Solution 2:

// is supported in all major browsers. Its very useful when you are developing a web based application and need to write code that works for both HTTP and HTTPS.

You could write for example: <script src="//myscript.js" /> and it will always work no matter which protocol you are using.

Solution 3:

I realize this question is old, but the accepted answer does not really answer the question.

Is that some kind of short-hand? Maybe it's something that's built in my browser (Chrome 14)?

Yes, it's a short-hand for whichever protocol the document was served over. It avoids the dreaded "This page contains both secure and nonsecure items. Do you want to display the nonsecure items?" message.

Is it safe to use double-slash instead of http and https?

Yes, all major browsers today support it.

It's generally useless against your own site, but can be very helpful for including resources from other sites (where absolute URL's are needed) but not having to worry about HTTP/HTTPS mix-mode.

It's also helpful if your document is served from both secure and nonsecure locations, like a dev site and production site.

For details, see http://www.paulirish.com/2010/the-protocol-relative-url/ (although that site does not recommend this technique any more, recommends to always use HTTPS)