有没有人有任何工作代码允许使用modernizr.load 或yepnope 来加载Google Maps API?
我可以使用modernizr 加载JQuery 和GMap3,但是除非我制作传统的脚本标签,否则Google Maps API 不起作用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Please help me load Google Maps API with modernizr!</title>
<style>
#map { width: 500px; height: 300px; }
</style>
<script src="/js/modernizr-2.6.2.min.js"></script>
</head>
<body>
<h1>Please help me load Google Maps API with modernizr!</h1>
<div id="map">
Placeholder
</div>
<script>
function pageInit() {
$("#map").gmap3({
map:{
options: {
center: [18.01714, -76.750113],
zoom: 15,
mapTypeId: google.maps.MapTypeId.TERRAIN,
}
}
});
}
</script>
<!-- I WANT TO REMOVE THE SCRIPT TAG BELOW AND REPLACE WITH MODERNIZR LOAD! -->
<script src="//maps.google.com/maps/api/js?sensor=false&language=en"></script>
<!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
<script>
Modernizr.load([{load: [
'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
'/js/gmap.jquery-5.1.1.min.js',
],complete: function () {loaded();}},]);
function loaded() {
$(document).ready(function() {
pageInit();
});
}
</script>
</body>
</html>
逻辑告诉我我应该在删除脚本标签后进行以下更改:-
Modernizr.load([{load: [
'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
'//maps.google.com/maps/api/js?sensor=false&language=en',
'/js/gmap.jquery-5.1.1.min.js',
但是,如果我这样做更改地图不会加载,我现在在 Javascript 控制台中收到此错误:-
Load denied by X-Frame-Options: http://maps.google.com/maps/api/js?sensor=false&language=en does not permit cross-origin framing.