4 ms·
Conversely, the protocol bit is relevant whenever your link is not domain- or protocol-relative, or when you can't be sure. And you can't be sure. Here's why:
by rufibarbatus 15y ago
Conversely, the protocol bit is relevant whenever your link is not domain- or protocol-relative, or when you can't be sure.
And you can't be sure. Here's why: if someone saves your page on their hard drive and you're using protocol-relative URLs, the implied "http" just became "file". (Which in fact may be a nice excuse for some clever hacks.)
Test it yourself! Save the following snippet to your computer and see how your browser resolves the URL:
<!DOCTYPE html>
<title>Testing 1 2 3</title>
<p><a href="//google.com/">Linky</a></p>
- sjs 15y agoYou're assuming people care about that use case. I think in most cases it's irrelevant.
- Vivtek 15y agoOh man. Are you really saying that corner cases are a priori negligible? That seems like a dangerous road to start down when you're discussing basic protocols!
- sjs 15y agoIf your use case entails people saving your site to disk then you have may not be able to use // for protocol relative links, but most people don't have to worry about such things. I'm saying that those who need to worry about such things should and the rest of us should not. Nothing more and nothing less.
- rawsyntax 15y agowget has switches to replace http with file when saving a website to disk
- teyc 15y agoHTML Base tag is your friend. http://www.w3schools.com/TAGS/tag_base.asp http://www.w3schools.com/TAGS/tag_base.asp
- sleepyhead 15y agoW3Schools is not your friend. http://w3fools.com/ http://w3fools.com/
- rufibarbatus 15y agoAnd here it is in the specification: http://dev.w3.org/html5/spec/Overview.html#the-base-element http://dev.w3.org/html5/spec/Overview.html#the-base-element And accordingly, adding `<base href="http://example.com/ http://example.com/ >` to that test above seems to work well on modern browsers.