我正在尝试使用Google Map的<iframe>
include,但是控制台由于不匹配而引发了多个错误,但是没有明显的不匹配,因此我假设它必须是Google Map的函数/过程。
根据this的说法,特别是对于maps.google.com,iframe脚本似乎有所更改。
控制台中的错误是这样的:(页面加载时我至少收到30个错误)
Unsafe JavaScript attempt to access frame with URL http://www.developer.host.com/ from
frame with URL https://maps.google.com/maps/msmsa=0&msid=
212043342089249462794.00048cfeb10fb9d85b995&ie=UTF8&t=
m&ll=35.234403,-80.822296&spn=0.392595,0.137329&z=10&output=embed.
The frame requesting access has a protocol of 'https', the frame being
accessed has a protocol of 'http'. Protocols must match.
由于我的网站是http而不是https,并且 map 网址是http,为什么会出现不匹配的情况,以及如何解决此问题以使其匹配?
最佳答案
这确实是由独立的Google Maps页面创建的可嵌入HTML代码的错误(maps.google.com->单击链接链按钮以获取基于iframe的HTML代码)。
如aSeptik在对您的问题的评论中所说,相应的错误报告can be found here。
如果您使用Maps API嵌入Google Map,则可以避免该错误。如果您直接在页面中或在嵌入式iframe中使用Maps API,则没有任何区别-两种方法都可以正常工作。
这是我在iframe中使用Maps API的其他 map 的an example。
这是您自己的 map (使用Maps API生成的中的an example)-嵌入在页面内。
实际上,Maps API所需的其他代码非常少:
<html>
<head>
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript' src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type='text/javascript'>
$(function(){
var myOptions = {
center: new google.maps.LatLng(35.201867,-80.836029),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
gMap = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
var kmlLayer = new google.maps.KmlLayer('https://maps.google.com/maps/ms?ie=UTF8&t=m&authuser=0&msa=0&output=kml&msid=212043342089249462794.00048cfeb10fb9d85b995');
kmlLayer.setMap(gMap);
});
</script>
</head>
<body>
<div id="map_canvas" style="width: 400px; height: 400px;"></div>
</body>
为了方便起见,我在这里使用了jQuery。
关于javascript - 获取http/https协议(protocol)以与Maps.google.com的<iframe>匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13555261/