Javascript iframe 未在引导弹出窗口中加载(模式)

Posted

技术标签:

【中文标题】Javascript iframe 未在引导弹出窗口中加载(模式)【英文标题】:Javascript iframe not load in bootstrap popup (modal) 【发布时间】:2015-08-13 20:08:55 【问题描述】:

我尝试在引导模式中加载WYSIWYG 编辑器,但未按如下方式加载iframe

<iframe id="desc_ifr" frameborder="0" src="javascript:""" allowtransparency="true" style="width: 100%; height: 410px; display: block;">
<html>
<head></head>
<body></body>
</html>
</iframe>

如何加载 iframe ?那可能吗? 我知道外面iframe 可以在下面的方法中加载。

$('.modal').on('shown.bs.modal',function()  
  $(this).find('iframe').attr('src','http://www.google.com')
)

有什么建议吗? 谢谢

【问题讨论】:

【参考方案1】:

Miuranga,看看这个 Fiddle 中的代码,看看你能不能把它放到你的 WYSIWYG 中,我不使用所以不确定如果您可以将代码复制到其中。

但是将 iframe 放入模态框的方法是在代码中。

请注意,在 Fiddle 中,代码实际上显示在 iframe 中,我相信您不能在另一个 iframe 中拥有 iframe。他们不会显示您要显示的网址。我已经测试过了,它确实有效。 像 google.com 这样的一些网址也被限制在 iframe 中显示。 这就是我使用 microsoft.com 的原因。

查看下面的运行代码片段。

<html>
    
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" >  


<body>
    
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#incidentModal">
  Launch demo modal
</button>
    
    
    
    
<!-- Modal -->
<div class="modal fade  bs-example-modal-lg" id="incidentModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        
        <div class="modal-content">
            <div class="modal-header  bg-primary">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Modal Title</h4>
    </div>
    <!-- /.modal-header -->
    <!--/.modal-header -->
    <div class="modal-body">
        <div class="container-fluid">
            <div class="modal-body row">
                <iframe id="desc_ifr" src="http://microsoft.com" style="width: 100%; height: 410px;" allowtransparency="true" >
                </iframe>          
            </div>
            
        </div>
        <!-- /.container-fluid-->
    </div>
    <!-- /.modal-body-->
    <div class="modal-footer bg-info">
        <button type="button" class="btn btn-success" data-dismiss="modal">Close</button>
    </div>
    <!-- /.modal-footer -->
</div>
<!-- /.modal-content-->
</div>
<!-- /.modal-dialog modal-lg-->
</div>
<!-- /.modal fade  bs-example-modal-lg -->
            
          <!--  </span></button></div></div>       -->   
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>            
</body>
</html>
            

【讨论】:

以上是关于Javascript iframe 未在引导弹出窗口中加载(模式)的主要内容,如果未能解决你的问题,请参考以下文章

在引导弹出框元素上设置事件侦听器

我可以在引导弹出窗口中显示 Twitter 提要吗?

键输入在引导弹出窗口输入中不起作用 - jquery

关闭引导弹出事件与 jquery 验证插件冲突

layer.open如何在iframe层关闭自己

iframe 未在 WKWebview 中加载