Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于http或https协议动态加载javascript_Javascript_Html_Https_Internet Explorer 8 - Fatal编程技术网

基于http或https协议动态加载javascript

基于http或https协议动态加载javascript,javascript,html,https,internet-explorer-8,Javascript,Html,Https,Internet Explorer 8,我有一个javascript文件位于不同的服务器中,我在http页面上包含该javascript文件 <script type="text/javascript" src="http://www.example.com/scriptfile.js"> <script type="text/javascript" src="https://www.example.com/scriptfile.js"> 问题是,例如,如果用户处于 http://www.example.c

我有一个javascript文件位于不同的服务器中,我在
http
页面上包含该javascript文件

<script type="text/javascript" src="http://www.example.com/scriptfile.js">
<script type="text/javascript" src="https://www.example.com/scriptfile.js">
问题是,例如,如果用户处于


http://www.example.com/home
(站点主页URL),现在当用户导航到另一个类似
https://www.example.com/transaction
(站点事务URL),我将脚本加载到https上,其工作正常。如果用户点击
https://www.example.com/home
(主URL更改为
https
),我在
http
上加载的脚本由于内容不安全而失败。欢迎任何处理此问题的建议。

此协议是可选的。如果省略它,浏览器将使用文档的任何协议。因此,您可以:

<script type="text/javascript" src="//www.mydomain.com/scriptfile.js">


将使用正确的协议。

为脚本使用协议相关URL:

<script type="text/javascript" src="//www.mydomain.com/scriptfile.js">


这将使用与调用页面相同的协议。

简单的解决方案是删除所有不安全的内容-只需在整个站点中使用https://并关闭端口80即可。@Floris我加载了带有“https”的javascript,而不管页面协议如何,它工作正常。谢谢