简体   繁体   English

iframe设置为click event。 它适用于打开页面后的首次点击。 但不适用于第二次。 请帮忙

[英]Iframe is set to click event . it works for First click after opening page. But not works for Second time. Please help On this

Using google map API V3, I have created One html page. 使用Google Map API V3,我创建了一个html页面。 It perfectly load gmap and i set button to load another web based map(mapmyindia.com) in Iframe. 它完美加载gmap,我设置了按钮以在iframe中加载另一个基于网络的地图(mapmyindia.com)。 basically it took the parameter(lat/long) from gmap and fetch into that frame to load. 基本上,它是从gmap中获取参数(经度/经度)并提取到该帧中进行加载的。 it works on 1st click and navigate the current gmap location. 第一次点击即可浏览并导航当前gmap位置。 After panning it another location and clicking to submit button it supposed to load current location of gmap into Iframe. 平移另一个位置并单击“提交”按钮后,应该将gmap的当前位置加载到iframe中。 But it doesn't work for second time. 但这第二次不起作用。 Kindly review my code and Help......! 请查看我的代码和帮助...!

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var map;
var marker
function initialize()
{
var mapOpt = {
  center:new google.maps.LatLng(20.6588,80.9562),
  zoom:6,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };
map=new google.maps.Map(document.getElementById("googleMap"),mapOpt);



google.maps.event.addListener(map, 'mousemove', function(event) {
        document.getElementById("pp").value = map.getCenter().lat() + "," +map.getCenter().lng();
        });


}
google.maps.event.addDomListener(window, 'load',initialize);
function copyText()
{
var xy=map.getCenter().lat()+ "," +map.getCenter().lng();

document.getElementById("latlng").value=xy;
document.getElementById("Zoom").value=map.getZoom();
}

function copyText1()
{
var xy=map.getCenter().lat()+ "," +map.getCenter().lng();
}



function OfferTwo(){
var mmy = map.getCenter().lng() + "," +map.getCenter().lat();
var sUrl = document.getElementById('offer2').src;
//var Zm= map.getZoom();
var Zm= '8';
document.getElementById('offer2').src = 'http://maps.mapmyindia.com/embed.html#current:'+Zm+','+mmy;
}


</script>
</head>
<body>
<input type= "text" ID=latlng>
<input type="text" ID=Zoom size="5" maxlength="2">
<input type ="text" ID="pp" >
<button onClick="copyText()">Submit</button>
<button onClick="OfferTwo()">Go To MMy</button>
<p Id="mmyurl">MamMyIndia Link</p>



<br><br>
<div id="googleMap"style="width:700px;height:500px;"></div>
<iframe id="offer2" Width="700" Height ="500"></iframe>

</body>
</html>

your script only changes the hash inside the url, when you click on the button the 2nd time the browser will try to jump to an anchor instead of reloading the map. 您的脚本只会更改url中的哈希值,第二次单击按钮时,浏览器将尝试跳至锚点,而不是重新加载地图。

Add a changing parameter to the QUERY_STRING: 向QUERY_STRING添加一个更改的参数:

document.getElementById('offer2').src 
  = 'http://maps.mapmyindia.com/embed.html?'+
     new Date().getTime()+'#current:'+Zm+','+mmy;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM