如何在需要时通过 HTTPS 包含 CSS 和 JS 文件? [英] How to Include CSS and JS files via HTTPS when needed?

查看:29
本文介绍了如何在需要时通过 HTTPS 包含 CSS 和 JS 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向页眉和页脚添加一个外部 CSS 文件和一个外部 JS 文件.加载 HTTPS 页面时,某些浏览器会抱怨我加载了不安全的内容.

I am adding an external CSS file and an external JS file to my headers and footers. When loading an HTTPS page, some browsers complain that I am loading unsecured content.

当页面本身是HTTPS时,有没有一种简单的方法可以让浏览器通过HTTPS加载外部内容?

Is there an easy way to make the browser load the external content via HTTPS when the page itself is HTTPS?

推荐答案

使用协议相对路径.

所以不是

<link rel="stylesheet" href="http://example.com/style.css">
<script src="http://example.com/script.js"></script>

不过如此

<link rel="stylesheet" href="//example.com/style.css">
<script src="//example.com/script.js"></script>

然后它将使用父页面的协议.

then it will use the protocol of the parent page.

这篇关于如何在需要时通过 HTTPS 包含 CSS 和 JS 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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