浏览器居中以及传参实例
window.showModelDialog可设置center参数为yes,保证其在子窗口在父窗口居中。
但是该参数只对IE浏览器有效,对火狐无效,只有通过计算模态窗口的居中位置。
解决办法
function openShowModalDialog(url,param,whparam,e){
// 传递至子窗口的参数
var paramObj = param || { };
// 模态窗口高度和宽度
var whparamObj = whparam || { width: 500, height: 500 };
// 相对于浏览器的居中位置
var bleft = ($(window).width() - whparamObj.width) / 2;
var btop = ($(window).height() - whparamObj.height) / 2;
// 根据鼠标点击位置算出绝对位置
var tleft = e.screenX - e.clientX;
var ttop = e.screenY - e.clientY;
// 最终模态窗口的位置
var left = bleft + tleft;
var top = btop + ttop;
// 参数
var p = "help:no;status:no;center:yes;";
p += 'dialogWidth:'+(whparamObj.width)+'px;';
p += 'dialogHeight:'+(whparamObj.height)+'px;';
p += 'dialogLeft:' + left + 'px;';
p += 'dialogTop:' + top + 'px;';
return showModalDialog(url,paramObj,p);
}
下面是一个使用该方法和传参的实例
Father.html
<head>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btn").click(function (e) {
var stuObj = { name: "xy", age: 22 };
var whObj = { width: 300, height: 200 };
var returnValue = openShowModalDialog("Son.html", stuObj, whObj, e);
if (returnValue) {
alert("传回来的name:" + returnValue.name);
}
});
});
</script>
</head>
<body>
<input id="btn" type="button" value="模态测试按钮" />
</body>
Son.html
<head>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
// 接收父窗口参数
var obj = window.dialogArguments;
alert("name:" + obj.name + "age:" + obj.age);
// 回传参数至父窗口
window.returnValue = { name: "lily", age: 21 };
window.close();
});
</script>
</head>
兼容性问题
发现问题
对话框在firefox仍可拉伸大小,并显示地址栏
解决办法
1 在Firefox地址栏中输入about:config
2 在Filter中输入dom.disable_window_open_feature.location
3 双击赋值,将true改为false
以上解决办法只能让firefox不显示地址栏,但仍可以拉伸。
其实window.showModalDialog本来就是ie的方法,FF对其支持难免有些不足。
分享到:
相关推荐
It was tested in the latest Google Chrome with the *Enable Experimental JavaScript* flag enabled in `chrome://flags/#enable-javascript-harmony` and in the latest Mozilla Firefox with the *dom.dialog_...
window.showModalDialog以及window.open用法简介
NULL 博文链接:https://shawnfree.iteye.com/blog/598885
window.showModalDialog以及window.open用法简介
针对window.showmodaldialog弹出窗体无刷新的详细使用
javascript代码模块之\Window.ShowModalDialog使用手册
window.showModalDialog的基本用法
window.showModalDialog&&open.docx
使用window.showModalDialog的程序员都知道,该方法可返回值。但是如果遇到跨域时,就返回为underfine。本文档通过iframe镶嵌页面解决该问题。
本文实例讲述了js的window.showModalDialog及window.open用法。分享给大家供大家参考。具体分析如下: 一、window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二、基本语法: window.open...
主页面用window.showModalDialog的时候,如果直接打开其它系统的页面,这时候别人的页面在window.returnValue=1;这样返回值的时候,主页面是取不到返回值的,原因就是因为跨域了.
JS 弹出对话框window.showModalDialog,级联方式,可以返回传值给页面
主要介绍了JavaScript中window.showModalDialog()用法详解,需要的朋友可以参考下
关于struts2里用javascript刷新window.showModalDialog的父页面
javascript代码模块之window.showModalDialog方法的使用
Window.ShowModalDialog使用手册_对话框 .txt 详细