【问题标题】:How to run HTTP sourced javascript on HTTPS site?如何在 HTTPS 站点上运行来自 HTTP 的 javascript?
【发布时间】:2017-04-16 19:39:55
【问题描述】:

我正在尝试通过 Cloud9 在线 IDE 运行 ConvNetJS example。包含的脚本在 HTML 中时有效,但在我如下链接时无效:

<html>
<head>
<title>minimal demo</title>
 
<!-- CSS goes here -->
<style>
body {
  background-color: #FFF; /* example... */
}
</style>

<!-- http://jquery.com/ -->
<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

<!-- http://getbootstrap.com/ -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<!-- import convnetjs library -->
<script src="//cs.stanford.edu/people/karpathy/convnetjs/build/convnet-min.js"></script>

<!-- app's own JavaScript -->
<!--script type="text/javscript" src="../static/script.js"></script-->

</head>
 
<body>
<div id="egdiv"></div>
</body>
</html>

script.js 中使用javascript:

function periodic() {
  var d = document.getElementById('egdiv');
  d.innerHTML = 'Random number: ' + Math.random();
};
 
var net; // declared outside -> global variable in window scope
$(function start() {
  // this gets executed on startup
  net = new convnetjs.Net();
 
  // example of running something every 1 second
  setInterval(periodic, 1000);
});

当我通过 IDE 运行应用程序时,我通过控制台收到以下警告:Mixed Content: The page at 'https://ide50-stephenwist.cs50.io/' was loaded over HTTPS, but requested an insecure script 'http://cs.stanford.edu/people/karpathy/convnetjs/build/convnet-min.js'. This content should also be served over HTTPS.

我该如何解决这个问题?我正在使用 chrome 并让它运行“不安全的脚本”。感谢您阅读本文,here's a puppy

【问题讨论】:

    标签: javascript jquery html http https


    【解决方案1】:

    如果没有此警告,您将无法加载不安全的内容。

    当您要加载一些不安全的外部内容时,您唯一能做的就是复制该内容并将其保存在您的安全域中。
    这样,您就可以从(您的)安全地址运行它。

    现在cs.stanford.edu安全网站。
    所以只要在//cs.stanford.edu/people/karpathy/convnetjs/build/convnet-min.js前面加上https:就不会出现警告了。

    【讨论】:

    • 感谢这消除了警告。链接时脚本未运行的问题似乎是 Flask 的一些问题。
    【解决方案2】:

    试试在你的cdn前面加上https:怎么样//cs.stanford.edu/people/karpathy/convnetjs/build/convnet-min.js

    https://cs.stanford.edu/people/karpathy/convnetjs/build/convnet-min.js 之类的东西可能会阻止 Chrome 警告?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2021-02-13
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      相关资源
      最近更新 更多