簡體   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

使用Google Map API V3,我創建了一個html頁面。 它完美加載gmap,我設置了按鈕以在iframe中加載另一個基於網絡的地圖(mapmyindia.com)。 基本上,它是從gmap中獲取參數(經度/經度)並提取到該幀中進行加載的。 第一次點擊即可瀏覽並導航當前gmap位置。 平移另一個位置並單擊“提交”按鈕后,應該將gmap的當前位置加載到iframe中。 但這第二次不起作用。 請查看我的代碼和幫助...!

<!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>

您的腳本只會更改url中的哈希值,第二次單擊按鈕時,瀏覽器將嘗試跳至錨點,而不是重新加載地圖。

向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