html5子页面无法弹出,弹出子页面,兼容ie
window.showModalDialog()(兼容ie的写法)模式窗口, 一种很特别的窗口,当它打开时,后面的父窗口的活动会停止,除非当前的模式子窗口关闭了, 才能操作父窗口.在做网页Ajax开发时,我们应该有时会用到它来实现表单的填写, 或做类似网上答题的窗口. 它的特点是,传参很方便也很强大,可直接调用父窗口的变量和方法.
使用方法:
vReturnValue = window.showModalDialog(路径 , 可选参数 ,框体的样式) ;
*注:
谷歌浏览器不支持window.showModalDialog()方法,在谷歌浏览器中用window.open()方法解决这个问题;
参数传递
father.html
父接受子传递的内容:
点击
function setPermission() {
var url = "child.html";
//居中问题
var dialogLeftValue = screen.width / 2 - 200 + "px";
var returnValue;
//判断是否兼容Chrome浏览器
if (navigator.userAgent.indexOf("Chrome") > 0) {
var width = 600;
var height = 350;
var top = (window.screen.height - 30 - height) / 2;
var left = (window.screen.width - 30 - width) / 2;
window.open(url, self,"width=" + width + ",height=" + height +",top=" + top + ",left=" +left);
}else{
returnValue = window.showModalDialog(url, "", "dialogHeight:350px;dialogWidth:600px;status:0;dialogTop:100px;dialogLeft:" + dialogLeftValue);
}
}
child.html
*{
margin: 0;
padding: 0;
}
.tab{width:100%;height:100%;}
.tab-menu{height:42px;width:100%;background: rgba(170,255,245,0.5);}
.tab-menu ul{list-style:none;}
.tab-menu li{
display:block;width:100px;float:left;border:1px solid #ddd;padding: 10px 0;
text-align: center;
border-bottom: none;
}
.tab-box div{width:100%;display:none;}
/* 让第一个框显示出来 */
.tab-box div:first-Child{display:block;}
/* 改变选项卡选中时候的样式 */
.change{background:#fff;}
#btnFooter{
width: 100%;
height: 50px;
position: fixed;
bottom:0;
display: flex;
justify-content: flex-end;
}
子传向父的内容:
点击
//设置父窗口的值
function setFather() {
if (navigator.userAgent.indexOf("Chrome") > 0) {
//获取元素之前必须用window.opener.
window.opener.document.getElementsByName("txt10")[0].value = document.getElementById("txt0").value ;
//获取父,中的对象
var mxwreport = window.opener.$("#ss").data("mxwreport");
}else{
window.dialogArguments.document.getElementsByName("txt10")[0].value = document.getElementById("txt0").value ;
}
}
子页面获取父页面的标签,并将自己的值赋值给父元素。
1:子页面获取父页面传入的值需要加前缀兼容ie的写法:
ie获取父元素标签 :window.dialogArguments.document.getElementsByName("txt10")[0].value;
其他浏览器(主要是chrome),获取父元素标签:
window.opener.document.getElementsByName("txt10")[0].value;
2:子页面传值给父页面兼容ie的写法:(需要借助步骤1的获取方法,其实就是子页面的值传递给父页面)
if (navigator.userAgent.indexOf("Chrome") > 0){
//其他浏览器的写法
window.opener.document.getElementsByName("txt10")[0].value = document.getElementById("txt0").value
}else{
//IE浏览器的写法
window.dialogArguments.document.getElementsByName("txt10")[0].value = document.getElementById("txt0").value ;
}
实际应用场景
*当父页面有2个以上的地方点击弹框都是同一的时候,需要获取点击框的id,来辨别点击的谁,这个时候我们需要一个全局变量,并且这个全局变量必须添加window中,window.id= whichtable.id;
父页面中的js
function OpenSetFont(whichtable)
{
window.fontId = whichtable.id;
if (navigator.userAgent.indexOf("Chrome") <0){
var mikecatstr = window.showModalDialog(url,whichtable.value ,"dialogWidth:430px;dialogHeight:300px;help:no;status:no;scrollbar:no;");
}else{
openwindow(url,self,430,300)
}
if (mikecatstr == null)
return;
if (mikecatstr == "Cancel")
return;
whichtable.value = mikecatstr;
}
function return_OpenSetFont(mikecatstr){
if (mikecatstr == null)
return;
if (mikecatstr == "Cancel")
return;
document.getElementById(window.fontId).value=mikecatstr;
}
子页面点击确定按钮的js
function Enter()
{
var vFont = getFontCss();
if (navigator.userAgent.indexOf("Chrome") <0){
window.returnValue = vFont;
}else{
window.opener.return_OpenSetFont(vFont)
}
window.close();
}
html5子页面无法弹出,弹出子页面,兼容ie相关推荐
- layui 子页面写弹出框覆盖父页面,以及给弹框中的表单赋值
咋说呢,因为对 layui 不太熟悉,这个弹出框搞了好久,看了好多解决方案,大致尝试了一下其中几种,在坑中无法自拔...总之终于搞出来了,在这里分享一下我的笔记. 着急的直接 戳这里 看解决代码. 尝 ...
- html5相对父元素定位,layer弹出层设置相对父级元素定位
layer弹出层默认是相对body固定定位的,可是项目中一般需要相对某个盒子相对定位,下面是个加载弹层例子: var loadIndex = layer.open({ type: 3, //3 表示加 ...
- %matplotlib inline是jupyter notebook里的命令, 意思是将那些用matplotlib绘制的图显示在页面里而不是弹出一个窗口
%matplotlib inline是jupyter notebook里的命令, 意思是将那些用matplotlib绘制的图显示在页面里而不是弹出一个窗口 终端输入jupyter notebook, ...
- iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案
iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案 参考文章: (1)iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案 (2)https://www.cn ...
- iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案—scrollIntoView()
iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案-scrollIntoView() 参考文章: (1)iOS下Html页面中input获取焦点弹出键盘时挡住input解决方案- ...
- Android --- 进入页面时,不弹出软键盘。当 EditText 被点击时不弹出软键盘,而是调用其他选择器,比如时间选择器等
功能需求: 1.进入页面时,不弹出软键盘 2.当 EditText 被点击时不弹出软键盘,而是调用其他选择器,比如时间选择器等 搜索百度测试: 1.百度上说用 editText.setInputTyp ...
- IOS上微信在输入框弹出键盘后,页面不恢复,下方有留白,有弹窗弹出时页面内容感应区域错位...
问题说明: ios中,键盘的弹起,页面会往上挪动,使输入框展示在页面中间,键盘隐藏页面会下挪恢复原状. 在微信移动端,ios页面不恢复,下方有留白. 收起键盘的瞬间,如果有弹窗弹出,此时时页面内容应区 ...
- JQuery弹出菜单时禁止页面(body)滚动
最近在做手机端的弹出菜单,但是菜单弹出来后滑动手机屏幕的话页面滚动总是会将菜单滑上去,体验非常不好,所以查了一下弹出菜单时禁止页面滚动的方法,整理如下: 方法一:弹出菜单时给body和html添加一个 ...
- 移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究
移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究 参考文章: (1)移动端和PC端弹出遮罩层后,页面禁止滚动的解决方法及探究 (2)https://www.cnblogs.com/ranyon ...
- 前台alert弹出页面,点击确定,关闭弹出框,整个页面进行刷新数据
前台alert弹出页面,点击确定,关闭弹出框,整个页面进行刷新数据location.reload(); $("#saveBatch").on("click", ...
最新文章
- 管理软件预警通知(Notification)功能的实现案例分析
- maven中spring-boot-dependencies变量名冲突
- RUNOOB python练习题9 如何在代码中加入砸瓦鲁多
- (转)IOS中获取各种文件的目录路径的方法
- Linux 进程 | 进程间的通信方式
- Java多线程系列---“JUC锁”01之 框架
- Ajax同步交互与异步交互
- 撩课-Web大前端每天5道面试题-Day35
- 生产线改造升级 蔚来部分10月份车辆订单将推迟交付
- webpack-md5-hash问题记录
- 二进制 文件 读入_数据挖掘--SPSS?Modeler数据的读入
- php和java环境整合
- C++模拟手机通信录管理系统
- Mac 破解zip压缩文件密码详解
- petalinux-build 报错解决
- 折下我的翅膀,送你飞翔
- MySQL数据库期末考试试题及参考答案(08)
- ctr多少正常_亚马逊点击率多少算正常?点击率怎么算?
- 北京自学考试计算机应用基础,北京教育考试院
- 【shell】Linux shell 之 打印99乘法表详解