没有“http | https”的网址 [英] URL without "http|https"

查看:385
本文介绍了没有“http | https”的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚从一位同事那里了解到,在链接中省略URL的http | https部分会使该URL使用它所使用的页面使用的任何方案。



<例如,如果我的页面是在 http://www.example.com 上访问的,那么我有一个链接(请注意' //'在前面):

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

该链接将转到 http://www.google.com



但如果我通过 https://www.example.com 使用相同的链接,它将转到 https://www.google.com



我想在网上查询有关这方面的更多信息,但我在思考一个好的搜索短语时遇到了麻烦。如果我搜索没有HTTP的URL,返回的页面是关于这个表单的网址:www.example.com,这不是我正在寻找的。



你会称这是一个无方案的URL吗?无协议的URL?



这适用于所有浏览器吗?我在FF和IE 8中进行了测试,它在两者中均有效。这是标准的一部分,还是我应该测试更多浏览器?

解决方案

协议相对网址。



您可能会在某些浏览器中收到异常的安全警告。



另请参阅 Wikipedia Protocol-relative URL 的简要定义。



At有一次,建议使用;但是要继续前进,应该避免。另请参阅StackOverflow问题,为什么要使用协议相对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, StackOverflow question, Why use protocol-relative URLs at all?

这篇关于没有“http | https”的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆