浏览器报Mixed Content错误的解决方法(日志)

2023年11月13日16:32:03 发表评论 43

错误:Mixed Content: The page at ‘https://XXX’ was loaded over HTTPS, but requested an insecure.......

https地址中,如果加载了http资源,浏览器将认为这是不安全的资源,将会默认阻止,这就会给你带来资源不全的问题了,比如:图片显示不了,样式加载不了,JS加载不了。

浏览器报Mixed Content错误的解决方法(日志)

 

控制台报错:

Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure frame 'http://music.163.com/m/outchain/player?type=2&id=2024225492&auto=1&height=66'. This request has been blocked; the content must be served over HTTPS.

浏览器报Mixed Content错误的解决方法(日志)

解决方案

第一种

1.首先确定引入的资源可以在http和https下都能访问

比如:http://music.163.com/outchain/player?type=2&id=2024225492

https://music.163.com/outchain/player?type=2&id=2024225492

2.在head里面写类似相对路径的形式

  1. <script src="music.163.com/outchain/player?type=2&id=2024225492" type="text/javascript"></script>

 

第二种

1.在页面中加入(meta)头中添加upgrade-insecure-requests

  1. <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

2.这将会把http请求转化为https请求。这样就不会再出现Mixed Content的错误了。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: