我在我的应用程序中使用谷歌地图 API。我正在从父窗口打开子窗口。此后,从子窗口(此窗口包含 map )用户将通过左键单击 map 来选择区域。在这次事件中,我将“经度”和“纬度”从子窗口更新到父窗口隐藏字段。这在 IE 和 Mozilla 中工作正常,但在 Google Chrome 中不起作用。
这里是代码(客户端窗口 JavaScript):
function placeMarker(location) {
marker = new google.maps.Marker({position: location, map: map, animation:google.maps.Animation.DROP});
var infowindow = new google.maps.InfoWindow({content: 'Latitude: ' + location.lat() + '<br>Longitude: ' + location.lng()});
infowindow.open(map,marker);
window.opener.document.getElementById("longitude").value=location.lat();
window.opener.document.getElementById("latitude").value=location.lng();
}
父窗口隐藏字段代码:
<input id="longitude" type="hidden" name="longitude" value=""/>
<input id="latitude" type="hidden" name="latitude" value=""/>
从父窗口打开子窗口代码:
<button type="button" onclick="popupwindow('googleMaps.html?longitude='+document.getElementById('longitude').value+'&latitude='+document.getElementById('latitude').value+'&areaName='+document.getElementById('sublocality_level_1').value+'&subAreaName='+document.getElementById('sublocality_level_2').value, 'Google maps', 915, 545);" class="btn">Locate your house on the Google maps</button>
打开windiw的Java脚本:
function popupwindow(url, title, w, h) {
if ((document.getElementById('longitude').value == '') && (document.getElementById('latitude').value == '')) {
alert('Please select proper area name.');
return false;
}
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
最佳答案
尝试通过“parent”变量访问父窗口。它应该可以在 Chrome 中运行。
parent.window.opener.document.getElementById("longitude").value=location.lat();
parent.window.opener.document.getElementById("latitude").value=location.lng();
关于javascript - Google Chrome 中的子窗口未更新父窗口详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661131/