【问题标题】:How to load google library using google.load over an https connection如何通过 https 连接使用 google.load 加载谷歌库
【发布时间】:2014-11-03 03:18:45
【问题描述】:

我必须加载一个谷歌地图库。 我已经使用了以下功能。

google.load("maps", "3", {other_params: "libraries=places&sensor=false", "callback": mapsLoaded });

但是在 https 连接上,它会在控制台中返回以下错误 [已阻止] 'https://mydomain.com?module=Contacts&action=index' 处的页面通过 HTTPS 加载,但运行了来自 'http://maps.googleapis.com/maps/api/js?v=3&libraries=places&sensor=false&callback=google.loader.callbacks.maps' 的不安全内容:此内容也应通过 HTTPS 加载。

如何解决上述错误?

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    因此,您的问题是您尝试在SSL 加密页面上使用google.load() 加载谷歌库,而您要提取的库的链接并不“安全”。从official documentation,您可以简单地尝试做(即通过https加载jsapi):

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    //The libraries should now be loaded over https.
    <script type="text/javascript">
     google.load("search", "1");
     google.load("jquery", "1.4.2");
     google.load("jqueryui", "1.7.2");
    </script>
    

    我正在检查 another blog post 是否通过 http/https 加载谷歌库,作者建议检查当前页面的 http/https 并相应地修改 DOM:

    <script language=”javascript” type=”text/javascript”>
    
     var prot =((“https:” == document.location.protocol) ? “https://” : “http://”);
     var key = “INSERT-YOUR-KEY“;
     document.write(unescape(“%3Cscript src='” + prot + “www.google.com/jsapi?key=” + key + “‘      type=’text/javascript’%3E%3C/script%3E”));
    
    </script>
    

    希望它能让你朝着正确的方向开始。

    【讨论】:

      猜你喜欢
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2011-12-06
      • 2010-11-15
      • 2018-06-02
      • 1970-01-01
      • 2013-05-16
      相关资源
      最近更新 更多