在我的网站上,如果使用 https 打开页面,Chrome 无法加载样式表。
例如,在页面 test.php 上我有以下 CSS 包括:
<link href="http://www.domain.com/css/mainstyle.css" rel="stylesheet" type="text/css">
它使用绝对路径,因为有很多 SEO、子目录等,所以像这样包含它比寻找相对路径容易得多。
如果我打开页面为 http://www.domain.com/test.php它工作正常,但如果我将其打开为 https://www.domain.com/test.php Chrome 拒绝加载样式表!
它适用于 Firefox 和 Safari。我可以理解 IE 是一种“有特殊需求”的浏览器,但为什么 Chrome 会这样做,我该如何解决?
使用 https://domain.com/css/mainstyle.css 调用 CSS 文件解决了问题,但真的有必要吗?
最佳答案
也许试试 Protocol Relative URLs
:
< link href="//www.domain.com/css/mainstyle.css" rel="stylesheet" type="text/css" >
The Protocol-relative URL - Paul Irish
希望对您有所帮助!
关于CSS 不适用于 Chrome 和 IE 中的 HTTPS 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17684229/