javascript - Google Chrome 中的子窗口未更新父窗口详细信息

标签 javascript google-maps google-chrome

我在我的应用程序中使用谷歌地图 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/

相关文章:

javascript - Phonegap + jQuery Mobile 改进

javascript - Puppeteer 无法获得完整的源代码

html - CSS 导航栏悬停未激活

android - 当我在圆半径内时做点什么

google-maps - 在谷歌地图上放一个按钮

javascript - 错误 :process_metrics. cc 未实现错误

javascript - 如何禁用 Chrome 应用程序上下文菜单

javascript - 通过鼠标移动绘制的矩形会在鼠标移动时不断绘制自身,同时显示之前的矩形

javascript - Jquery 事件冒泡复选框

google-maps - 更改 Google map 以重复使用单个信息窗口,而不是创建多个