简体   繁体   English

加载获取远程链接到引导模态框

[英]load get remote link into bootstrap modal box

I need to load google map link(remote) after open modal box. 打开模态框后,我需要加载google map链接(远程)。

HTML: HTML:

<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>

<div class="modal" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                 <h4 class="modal-title">Modal title</h4>

            </div>
            <div class="modal-body">Location:
                <input type="text" id="us2-address" style="width: 200px" />Radius:
                <input type="text" id="us2-radius" />
                <div id="us2" style="height: 400px;"></div>Lat.:
                <input type="text" id="us2-lat" />Long.:
                <input type="text" id="us2-lon" />
            </div>
            <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a>
 <a href="#" class="btn btn-primary" id="save-changes">Save changes</a>

            </div>
        </div>
    </div>
</div>

JS: JS:

var stillPresent = false;
$('#myModal').on('shown.bs.modal', function (e) {
       if(stillPresent == false){
               $('#us2').locationpicker({
            location: {
                latitude: 46.15242437752303,
                longitude: 2.7470703125
            },
            radius: 300,
            inputBinding: {
                latitudeInput: $('#us2-lat'),
                longitudeInput: $('#us2-lon'),
                radiusInput: $('#us2-radius'),
                locationNameInput: $('#us2-address')
            }
        });
            stillPresent = true;
        }
    })

google map link : http://maps.google.com/maps/api/js?sensor=false&libraries=places google map链接: http : //maps.google.com/maps/api/js?sensor=false&libraries=places

DEMO : http://jsfiddle.net/Lzv7w/9/ 演示: http : //jsfiddle.net/Lzv7w/9/

if I add google map link into external resources jsfiddle worked. 如果我添加谷歌地图链接到外部资源jsfiddle工作。 but I need to load google map link after open modal. 但我需要在打开模式后加载google map链接。

How to load this ? 如何加载呢?

Google has a nice tutorial here that may help you. Google 在这里有一个不错的教程,可能会对您有所帮助。 And the code below should fix your problem. 下面的代码应该可以解决您的问题。 Note that it may not work jsfiddle, but it should work on your real page. 请注意,它可能无法在jsfiddle中使用,但应该可以在您的实际页面上使用。

var stillPresent = false;
function initialize() {
    if (stillPresent == false) {
        $('#us2').locationpicker({
            location : {
                latitude : 46.15242437752303,
                longitude : 2.7470703125
            },
            radius : 300,
            inputBinding : {
                latitudeInput : $('#us2-lat'),
                longitudeInput : $('#us2-lon'),
                radiusInput : $('#us2-radius'),
                locationNameInput : $('#us2-address')
            }
        });
        stillPresent = true;
    }
}

function loadScript() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://maps.google.com/maps/api/js?sensor=false&libraries=places&callback=initialize';
    document.body.appendChild(script);
}
$('#myModal').on('shown.bs.modal', function(e) {
    loadScript();
});

Also, here is a link to a similar question. 此外, 是指向类似问题的链接。

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

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