在iframe中使bootstrap的模态框在父页面弹出
2017-08-07 01:51
435 查看
在iframe中使bootstrap的模态框在父页面弹出
这几天在写项目的中,页面使用了iframe,然而在子页面中使用bootstrap的模态框时发现:弹出的模态框位置是以子页面为标准居中的,并且遮罩层也只有子页面那一部分,整个页面简直无法直视,所以思考可以可以让模态框以父页面为标准弹出,经过在网上查找资料,总结了一种解决方法。效果展示
修改前页面修改后页面
实现思路
要想使模态框在顶级页面打开,我想到的方法是使bootstrap的模态框弹在父页面弹出即可。首先我们将需要弹出的div单独写一个页面,当子页面需要弹出时,在父页面弹出div即可。
将模态框单独写为一个页面
主页面<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <div class="modal fade" id="ajax" role="basic" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> </div> </div> </div> </body> <script> $("#ajax").modal({ remote: "./model.html" }); </script> </html>
模态框页面
<div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> 这是模态框 </div> <div class="modal-footer"> <button type="button" class="btn btn-primary">保存</button> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> </div> </div>
这样就可以将模态框的div单独写为一个页面
修改主页面,加入子页面
修改后主页面<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <table width="100%" height="720px" border="1"> <tr> <td> <iframe id="iframe1" name="iframe1" src="iframe1.html" width="100%" height="100%"></iframe> </td> <td></td> </tr> <tr> <td></td> <td> <iframe name="iframe2" src="iframe2.html" width="100%" height="100%"></iframe> </td> </tr> </table> <input type="text" id="textId" value="234" /> <div class="modal fade" id="ajax" role="basic" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> </div> </div> </div> </body> <script> function modalOut(url) { $("#ajax").modal({ remote: url; }); } </script> </html>
这样主页面就有2个子页面,并且将弹出模态框的方法封装至modalOut(url)方法中
子页面弹出模态框
当子页面需要弹出模态框时,加载父页面中的modalOut(url)方法即可:子页面js如下
var _iframe = window.parent; _iframe.modalOut('xxx.html');
以上就是解决子页面中弹出模态框无法覆盖全部页面的解决办法,
注意:所以html中未加载js,请自行加载bootstrap相关的js。
相关文章推荐
- 用Bootstrap框架弹出iframe页面 在弹出的模态框中载人iframe页面
- 在iframe中使bootstrap的模态框在父页面弹出问题
- 在ASP.NET中使用IFRAME+DIV,可以实现在同一页面使用弹出(模态)窗口
- rails4使用bootstrap的模态框插件,结合ajax做出从弹出框选取内容返回给原页面的效果
- 解决Bootstrap一个页面弹出的模态框嵌套多个模态框时,样式混乱,按钮不能点击。
- (精)在ASP.NET中使用IFRAME+DIV,可以实现在同一页面使用弹出(模态)窗口
- 自己封装的Thinkphp+Bootstrap 模态iframe其他页面
- Bootstrap的模态框遮罩在iframe子页面弹出时不能覆盖父页面的解决方法
- 关于bootstrap 在MVC里 模态框里加载iframe页面做编辑的时候
- bootstrap 弹出包含iframe模态窗口的修改
- bootstrap3-iframe-modal子页面在父页面显示模态框
- Bootstrap 模态框 + iframe > 打开子页面 > 数据传输/关闭模态框
- 父页面带滚动条时,iframe的bootstrap模态框定位问题
- bootstrap在iframe框架中实现由子页面在顶级页面打开模态框(modal)
- 【WeChat】微信页面弹出键盘后iframe内容变空白
- bootstrap中模态框上弹出另外一个模态框
- bootstrap-href触发模态弹出窗元素
- iOS开发中ViewController的页面跳转和弹出模态
- AngularJS页面【uib-dropdown】控件在模态窗口(弹出窗)中无法使用问题
- bootstrap模态弹出框学习笔记(1-9 模态弹出框--模态弹出窗的使用(data-参数说明))