1

我有一个为 SugarCRM 工作的开源包,它使用 Google Map API。用户报告说 Chrome 浏览器存在错误(https 加载问题)。当 SugarCRM URL 使用 https 协议定义且 Maps API URL 为 http 时,会出现此问题。因为这是一个已安装的包,它可以与 http 或 https 协议一起使用;这取决于它的安装位置。

示例 SugarCRM URL:

https://www.mydomain.com/index.php

当前的 Google Maps API 调用:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

我正在考虑将其简单地更改为 https,但这会解决问题吗?我是否应该编写一些逻辑来检查站点的 URL(来自 SugarCRM 配置)的 http 或 https 并使其匹配协议?jquery 等其他外部 JS 文件呢?

另外,我看到人们使用 // 应该让浏览器决定协议?是否与所有最新的浏览器兼容?例如 Firefox、IE、Chrome 和 Safari?

4

1 回答 1

2

Using a Protocol Relative URL (i.e. the //) is I believe supported in pretty much all recent mainstream browsers (except possibly IE6) so I would say it's perfectly safe. You can read more about them from Paul Irish here: http://paulirish.com/2010/the-protocol-relative-url/

If you did want to do a check yourself it is a fairly simple check in javascript, something like this but obviously for maps instead of ga:

ga.src = ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js';

(as found here: http://mathiasbynens.be/notes/async-analytics-snippet#protocol-check)

Note that if you're on google maps API v2 I think you had to do it this way as the url was different for ssl, but it looks like you're on the current version so should be fine.

I believe twitter used to have a check like the one above for their tweet buttons but now use protocol relative urls too. The HTML5 Boilerplate template also uses then so I'd say you're in good company if you decide to use them.

于 2013-04-11T00:31:44.327 回答