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

查看:297
本文介绍了如何在需要时通过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天全站免登陆