2014-09-04 5 views
1

내 애플리케이션에 Google지도 API를 사용하고 있습니다. 부모 창에서 자식 창을 여는 중입니다. 이 자식 창 (이 창에지도 포함)에서이 후지도에서 마우스 왼쪽 버튼을 클릭하여 영역을 선택합니다. 이 이벤트에서 나는 자식 윈도우에서 부모 창 숨겨진 필드로 "경도"와 "위도"를 업데이트하고 있습니다. 이것은 IE와 Mozilla에서는 잘 작동하지만 Google 크롬에서는 작동하지 않습니다.부모 창 세부 정보가 Chrome의 하위 창에서 업데이트되지 않습니다.

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> 

자바 여기

코드 (클라이언트 창 자바 스크립트)입니다 바람을 여는 스크립트 :

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); 
    } 

답변

1

'부모'변수를 통해 상위 창에 액세스를 시도하십시오. Chrome에서 작동해야합니다.

parent.window.opener.document.getElementById("longitude").value=location.lat(); 
parent.window.opener.document.getElementById("latitude").value=location.lng(); 
+1

부모를 추가 한 후에도 여전히 동일한 문제가 발생하지 않습니다. – user995656

+2

문제점을 발견했습니다. 정상적인 프로토 타입 HTML에서는 작동하지 않습니다. Apache Tomcat과 같은 서버에이 코드를 배포하면 정상적으로 작동합니다. 하지만 그 이유는 정상적인 페이지를 누른 다음 부모 창을 업데이트 할 수없는 이유를 찾을 수 없습니다. – user995656

관련 문제