HTTPS 混合内容问题及解决方案
当 HTTPS 页面加载 HTTP 资源时,就会产生混合内容(Mixed Content)。浏览器会阻止不安全的请求,导致页面功能异常。本文介绍混合内容的类型、排查方法和解决方案。 什么是混合内容 HTTPS 页面中通过 HTTP 加载的资源称为混合内容: 1 2 3 4 <!-- HTTPS 页面中的混合内容 --> <script src="http://example.com/script.js"></script> <img src="http://example.com/image.jpg"> <link rel="stylesheet" href="http://example.com/style.css"> 混合内容类型 混合被动内容(Mixed Passive Content) 低风险资源,浏览器通常只显示警告: <img> 图片 <audio> / <video> 媒体 <object> 子资源 混合主动内容(Mixed Active Content) 高风险资源,浏览器会直接阻止: <script> 脚本 <link> 样式表 <iframe> 内嵌页面 XMLHttpRequest / Fetch 请求 <frame> / <object> 加载的页面 排查方法 浏览器控制台 打开开发者工具(F12),查看 Console 和 Security 面板: 1 2 3 Mixed Content: The page at 'https://example....