What is the effect of starting a url with “//”, and leaving out “http:” [duplicate]

一世执手 提交于 2019-11-27 02:50:25

问题


Possible Duplicate:
Absolute URLs omitting the protocol (scheme) in order to preserve the one of the current page

I recently noticed that the embed codes for the "like" and "tweet" buttons don't include the http protocol. For example:

<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>

<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=555";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

Why do they do this?


回答1:


Depending on the protocol used by your website, http, https, spdy, etc, it will use the same protocol than your website is using. In other words it will use the currently used protocol.



来源:https://stackoverflow.com/questions/8343942/what-is-the-effect-of-starting-a-url-with-and-leaving-out-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!