且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

没有“http|https"的网址

更新时间:2023-11-27 18:28:16

协议相对 URL

您可能会在某些浏览器中收到不寻常的安全警告.

另请参阅***协议相关网址,了解简要定义.>

有一次,有人推荐;但展望未来,应该避免.

另见堆栈溢出问题 为什么要使用相对协议的 URL?.

I just learned from a colleague that omitting the "http | https" part of a URL in a link will make that URL use whatever scheme the page it's on uses.

So for example, if my page is accessed at http://www.example.com and I have a link (notice the '//' at the front):

<a href="//www.google.com">Google</a>

That link will go to http://www.google.com.

But if I access the page at https://www.example.com with the same link, it will go to https://www.google.com

I wanted to look online for more information about this, but I'm having trouble thinking of a good search phrase. If I search for "URLs without HTTP" the pages returned are about urls with this form: "www.example.com", which is not what I'm looking for.

Would you call that a schemeless URL? A protocol-less URL?

Does this work in all browsers? I tested it in FF and IE 8 and it worked in both. Is this part of a standard, or should I test more browsers?

Protocol relative URL

You may receive unusual security warnings in some browsers.

See also, Wikipedia Protocol-relative URLs for a brief definition.

At one time, it was recommended; but going forward, it should be avoided.

See also the Stack Overflow question Why use protocol-relative URLs at all?.