简体   繁体   English

Bootstrap Modal对话框不显示

[英]Bootstrap Modal dialog not displaying

I am trying to make it so when a user clicks on a button, a modal dialog opens and another site is loaded within that dialog.. I have used some tutorials and still cant seem to get it working correctly.. currently when i click the button, the screen just goes slightly grey but no dialog appears.. can anyone see where im going wrong? 我正在尝试这样做,以便当用户单击按钮时,打开一个模式对话框,并且在该对话框中加载了另一个网站。.我使用了一些教程,但似乎仍然无法使其正常工作。按钮,屏幕只是变成灰色,但没有出现对话框..有人能看到我在哪里出错吗?

<a href="www.google.co.uk" class="btn bootpopup" title="This is title" target="popupModal2">Visit site</a>

<div id="popupModal2" class="modal hide fade" tabindex="-1" role="dialog">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
            <h3>Add new Item</h3>
    </div>
    <div class="modal-body">
      <iframe src="" style="zoom:0.60" frameborder="0" height="250" width="99.6%"></iframe>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal">OK</button>
    </div>

javascript javascript

        $('.bootpopup').click(function(){
    var frametarget = $(this).attr('href');
  var targetmodal = $(this).attr('target');
  if (targetmodal == undefined) {
    targetmodal = '#popupModal';
  } else { 
    targetmodal = '#'+targetmodal;
  }
  if ($(this).attr('title') != undefined) {
    $(targetmodal+ ' .modal-header h3').html($(this).attr('title'));
    $(targetmodal+' .modal-header').show();
  } else {
     $(targetmodal+' .modal-header h3').html('');
    $(targetmodal+' .modal-header').hide();
  }  
    $(targetmodal).on('show', function () {
        $('iframe').attr("src", frametarget );   
    });
    $(targetmodal).modal({show:true});
  return false;

});

I found below java script code(cross domain loading code) from this link . 我从此链接中找到了以下Java脚本代码(跨域加载代码)。 In this link go and review the answer given by Manoz. 在此链接中,回顾Manoz给出的答案。 And for creating bootstrap modal dynamically go to this link . 要动态创建引导模态,请转到此链接 Bootstrap modal link will help you to create each and every modal dynamically rather then creating them manually everytime. Bootstrap模态链接将帮助您动态创建每个模态,而不是每次手动创建它们。

 function openSite() { BootstrapDialog.show({ title: 'Level 2 Title', message: $('<div id="loadCrossoriginHere"></div>'), onshown: function() { $.ajaxSetup({ scriptCharset: "utf-8", //maybe "ISO-8859-1" contentType: "application/json; charset=utf-8" }); $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://google.co.uk') + '&callback=?', function(data) { $("#loadCrossoriginHere").html(data.contents); }); } }); } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.35.3/css/bootstrap-dialog.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.35.3/js/bootstrap-dialog.min.js"></script> <button type="button" class="btn btn-primary" onclick="openSite()">Visit Site</button> 

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

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