2017-07-30 24 views
3

我有一個iframe地圖,它的座標和兩個輸入值和它們的值,這些值來自數據庫,我想將這些值傳遞給地圖座標,我該怎麼做?這裏是我的代碼:將經緯度和長度傳遞給iframe

<iframe width="100%" height="600" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q='+MYLAT+','+MYLONG+'&hl=es;z=14&amp;output=embed"></iframe> 
 

 
<form> 
 
<div class="form-group"> 
 
<input type="hidden" class="form-control" value="Latitude" id="lat"> 
 
</div> 
 
<div class="form-group"> 
 
<input type="hidden" class="form-control" value="Longitude" id="long"> 
 
</div> 
 
</form>

+0

的src一個鈕!? – M0ns1f

回答

0

你不能直接將屬性的iFrame的DOM節點,由於安全方面的原因。您需要找到其他方式將它們傳遞給地圖。也許用參數加載地圖。

+0

你能告訴我怎麼樣? – jessica

0

function changeloc() 
 
{ 
 
var lat = document.getElementById('lat').value; 
 
var long = document.getElementById('long').value; 
 
var src = "https://maps.google.com/maps?q="+lat+","+long+"&hl=es;z=14&amp;output=embed"; 
 
document.getElementById('map').src = src; 
 
}
<iframe width="100%" height="600" frameborder="0" scrolling="no" marginheight="0" id="map" marginwidth="0" src="https://maps.google.com/maps?q='+MYLAT+','+MYLONG+'&hl=es;z=14&amp;output=embed"></iframe> 
 

 
<form> 
 
<div class="form-group"> 
 
<input type="text" class="form-control" value="Latitude" id="lat"> 
 
</div> 
 
<div class="form-group"> 
 
<input type="text" class="form-control" value="Longitude" id="long"> 
 
</div> 
 
</form> 
 
<button onclick='changeloc();'>Change loc</button>

試試這個我加你在頁面從一個php文件加載的改變IFRAME

+0

未捕獲的DOMException:阻止了源於訪問跨源框架的框架。 – jessica

+0

因爲你運行它在計算器中,複製 – M0ns1f

+0

代碼段中生成的url,它給了我同樣的錯誤 – jessica

相關問題