Javascript 如何修复“尝试从未经身份验证的源加载脚本的页面”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36898894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:41:24  来源:igfitidea点击:

How to fix "page trying to load scripts from unauthenticated source"

javascriptphphtmlerror-handlingwebpage

提问by isubhamb

How can I fix this in my PHP page that contains ad scripts?

如何在包含广告脚本的 PHP 页面中解决此问题?

I have added scripts. It worked fine in HTTP but after I switched my site to HTTPS, nothing is appearing.

我添加了脚本。它在 HTTP 中运行良好,但在我将我的网站切换到 HTTPS 后,什么也没有出现。

This is the error in dev console:

这是开发控制台中的错误:

Failed to load resource: the server responded with a status of 404 (Not Found) index.php:1

Mixed Content: The page at 'https://myrevenuebank.com/index.php'was loaded over HTTPS, but requested an insecure script 'http://resources.infolinks.com/js/infolinks_main.js'. This request has been blocked; the content must be served over HTTPS.

加载资源失败:服务器响应状态为 404(未找到)index.php:1

混合内容: 页面'https://myrevenuebank.com/index.php'已通过 HTTPS 加载,但请求了不安全的脚本'http://resources.infolinks.com/js/infolinks_main.js'。此请求已被阻止;内容必须通过 HTTPS 提供。

<script type="text/javascript">
  var infolinks_pid = 2735394;
  var infolinks_wsid = 0;
</script>
<script type="text/javascript" src="http://resources.infolinks.com/js/infolinks_main.js"></script>

回答by FrontMonkey

click View > Developer > JavaScript Console. Send us what errors you have in developer Console. try to use https rather than http in script link. also you can try to download the script and put it in your server.

单击查看 > 开发人员 > JavaScript 控制台。将您在开发者控制台中遇到的错误发送给我们。尝试在脚本链接中使用 https 而不是 http。您也可以尝试下载脚本并将其放入您的服务器。

  1. you have 404 on menu.css (missing file)
  2. you are loading http script from https website. change http://resources.infolinks.com/js/infolinks_main.jsto https://resources.infolinks.com/js/infolinks_main.js
  1. 您在 menu.css 上有 404(缺少文件)
  2. 您正在从 https 网站加载 http 脚本。将http://resources.infolinks.com/js/infolinks_main.js更改 为https://resources.infolinks.com/js/infolinks_main.js

回答by Mike

The reason is because browsers will block insecure content when accessing a secure page unless the user specifically allows that content.

原因是浏览器在访问安全页面时会阻止不安全的内容,除非用户明确允许该内容。

You are trying to access http://resources.infolinks.com/js/infolinks_main.jsfrom a secure connection, but that will not work. Instead change the URL to //resources.infolinks.com/js/infolinks_main.jswithout the protocol.

您正在尝试http://resources.infolinks.com/js/infolinks_main.js通过安全连接进行访问,但这不起作用。而是将 URL 更改为//resources.infolinks.com/js/infolinks_main.js不使用协议。

Note: This will only work for things that can be accessed using exactly the same URL with both httpand https, which is the case here. If the script is only available over http, you will not be able to access it via httpsand you would have to save it on your server instead of loading it from a remote server.

注意:这仅适用于可以使用与http和完全相同的 URL 访问的内容https,这里就是这种情况。如果脚本只能通过http,您将无法通过访问它https,您必须将其保存在您的服务器上,而不是从远程服务器加载它。