传递数据 id 以引导模式并使用它 iframe url
Passing data-id to bootstrap modal and use it iframe url
我正在尝试在引导模式中显示地图。 我有包含位置链接的记录列表。 单击位置时,它将在模态窗口中显示地图位置。 我成功地将值传递给模态窗口。 但无法在 iframe SRC 链接中使用。 下面是我的代码。
<a href="#myMapModal" class="btn fblack" data-toggle="modal" data-id="<?=$row['lat']?>,<?=$row['lng']?>">Location on Map</a>
和我的j查询
<script>
$('#myMapModal').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
$(this).find('#latlng').text(location);
});
</script>
我正在尝试将返回值放在 URL 中
<iframe width="570" height="300" frameborder="0" style="border:0;" src="https://www.google.com/maps/embed/v1/place?q=#latlng&key=xxxxxxxxxxx"></iframe>
我给了q=#latlng
我可以使用<div id="latlng"></div>
打印
但我无法在 URL 中使用。
使用此脚本,了解有关 google API 的更多信息
<script>
$(function(){
$('#myMapModal').$('.bs-example-modal-lg').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
var newUrl = 'https://www.google.com/maps/embed/v1/view?key=1234¢er='+location;
console.log(newUrl);
$(this).find('iframe').attr('src',newUrl);
});
});
</script>
我做了什么来让它工作。
<script>
$('#myMapModal').on('show.bs.modal', function (e) {
var location = $(e.relatedTarget).attr('data-id');
$.ajax({
type : 'post',
url : 'map-list.php', //Here you will fetch records
data : 'rowid='+ location, //Pass $id
success : function(data){
$('#fetched-data').html(data);//Show fetched data from database
}
});
});
</script>
在地图上列表上.php
<?php
//Include database connection
if($_POST['rowid']) {
$eveid = $_POST['rowid']; //escape string
?>
<iframe width="570" height="300" frameborder="0" style="border:0;" src="https://www.google.com/maps/embed/v1/place?q=<?=$eveid?>&key=AIzaSyCoqMKgHRLWPQAwjGq0dzRhSg6e4UlrgE4"></iframe>
<?
}
?>
在模态体中
<div id="fetched-data"></div>
相关文章:
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- 重定向iFrame中的父URL
- iFrame url更改时执行函数
- 在iframe中加载url并添加一个类
- 如何使用iFrame在不同的域中匹配URL
- 编码url并显示在iframe中
- 是否可以添加<脚本>添加'_someTag'到iFrame中的URL
- 如何调整跨域url中iframe的大小
- 一些url没有在iframe中打开
- 我想从iframe获取url
- 嵌入iframe URL以在wordpress中包含当前用户id
- 绕过同源策略,从跨域iframe中获取页面的顶部URL
- iframe url在浏览器上打开
- 如何检查 iframe 中的锚标记是否包含 URL
- IFrame 从不同域上的父 url 获取参数
- 将当前页面 URL 传递给 iframe 地址
- 如何使用 React 替换 iframe 的 URL
- 由 URL 触发的来自 iFrame 的 JavaScript 重定向
- 为什么当我尝试为iframe-src属性构建URL时,AngularJS会抛出错误
- 只允许表单提交,如果从某个URL?(iframe Laravel)