http content on a https page - Mixed content

大兔子大兔子 提交于 2019-11-28 06:20:41

问题


I was wondering how I should do this.

I have some https pages, but need to call in some http content from my CDN provider.
The content I am wanting to load via http is javascript, css and images.

Now when doing this at the moment, some browsers give a mixed content warning, and ask if to show just secure or all content. What I would like to do, is get around this, and give no warning, but keep the https page.

All I can come up with is:
Make a PHP script that uses cURL or file_get_contents, and get the server to load the page in it.

But the problem with this, is it makes the CDN a bit pointess on https pages (I was thinking signup and login at the moment), as it would send the server IP, which is UK and not the visitor which could be from the USA.

Can anyone think of another way to mix the content, but get around the warnings, other then asking each visitor, to change there settings, which I think is a no go.

Thanks.
Garry


回答1:


If you want to use a CDN, you'll need one that supports HTTPS unfortunately.

Google Libraries provides a number of well-known libraries (e.g. jQuery) over HTTPS.




回答2:


I know this has already had an answer accepted, but I think the following is a better solution:

Try using protocol-less Urls.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js" type="text/javascript"></script>

You can do the same with CSS:

<link href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.20/themes/base/jquery.ui.core.css" type="text/css" rel="stylesheet" />

Note the lack of https or http in the urls. The browser will determine the appropriate protocol. No more mixed content warnings / errors.



来源:https://stackoverflow.com/questions/10554775/http-content-on-a-https-page-mixed-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!