URL の先頭に二重スラッシュを使用してプロトコルを継承することには、何か欠点がありますか? 例: src="//domain.example" 質問する

URL の先頭に二重スラッシュを使用してプロトコルを継承することには、何か欠点がありますか? 例: src=

I have a stylesheet that loads images from an external domain and I need it to load from https:// from secure order pages and http:// from other pages, based on the current URL. I found that starting the URL with a double slash inherits the current protocol. Do all browsers support this technique?

HTML ex:

<img src="//cdn.domain.example/logo.png" />

CSS ex:

.class { background: url(//cdn.domain.example/logo.png); }

ベストアンサー1

If the browser supports RFC 1808 Section 4, RFC 2396 Section 5.2, or RFC 3986 Section 5.2, then it will indeed use the page URL's scheme for references that begin with "//".

おすすめ記事