javascript 在 https 页面上通过 http 加载 Chrome 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20701268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 19:02:35  来源:igfitidea点击:

Chrome loading script over http on https page

javascripthtmlgoogle-chromesslhttps

提问by Nikolay Fominyh

We have absolute paths in template, i.e.:

我们在模板中有绝对路径,即:

<link rel="stylesheet" href="/media/css/ui.css?v=3" />

When I'm trying to open https page - I get following error:

当我尝试打开 https 页面时 - 我收到以下错误:

[blocked] The page at 'https://{{ full_site }}/{{secure_page}}' was loaded over HTTPS, 
but ran insecure content from 'http://{{full_site }}/media/css/ui.css?v=3': 
this content should also be loaded over HTTPS.

But path https://{{full_site }}/media/css/ui.css?v=3is available...

但是路径https://{{full_site }}/media/css/ui.css?v=3是可用的...

Tell me, why chrome trying to load content over http on https page? And how to force it to load scripts over https on relative paths?

告诉我,为什么 chrome 试图在 https 页面上通过 http 加载内容?以及如何强制它在相对路径上通过 https 加载脚本?

UPDPage loads perfectly in firefox. So this is only chrome issue. All paths are relative.

UPD页面在 Firefox 中完美加载。所以这只是铬问题。所有路径都是相对的。

采纳答案by sachinjain024

This could be the reason that your CSS file ui.cssmay be referring to resources (e.g. images) via background or background-imageproperty which is loading insecure content (Content from HTTP servers)

这可能是您的 CSS 文件ui.css可能通过background or background-image加载不安全内容(来自 HTTP 服务器的内容)的属性引用资源(例如图像)的原因

If you have resources on your site, use Relative Protocol Linkslike

如果您的站点上有资源,请使用相对协议链接,例如

url(//example.com/images/some_image.png)

Similarly, update your link to use relative protocol link like

同样,更新您的链接以使用相关协议链接,例如

<link rel="stylesheet" href="//{{full site}}/media/css/ui.css?v=3" />