在web页面中需要弹出一些模态窗口,对于如何应用大体做了一下总结。
打开模态窗口
var result = showModalDialog("b2.htm","dialogWidth:270px;dialogHeight:140px;status:'no'"); //显示dialog窗,result变量为此窗返回值数组
从模态窗口返回值
window.returnValue=”aaa” //返回aaa,可直接从表单里获取数据如document.all.textfield.value;
window.close(); //关闭模态窗口
向模态窗口传值
传递
var args = new array();args[0]=”a”; //第一个参数为”a”
args[1]=”b”; //第二个参数为”b”
url="a2.htm";
state="dialogWidth:200px;dialogHeight:100px;status:'no'";
var result = showModalDialog(url, args,state);
窗口中接收
v1=window.dialogArguments[0];
v2=window.dialogArguments[1];
模态窗口中的页面提交问题
在模态窗口中,如有提交按钮,点击后会弹出新的页面。解决此问题有两种方法:
1、在head中,添加注意:不要在form中再添加target="_self" 否则失效
2、把弹出的窗口页面做成框架网页,去加载要展示的网页
test6.htm
===================
window.showModalDialog( "test7.htm ")
test7.htm
===================
if(window.location.search) alert(window.location.search)
test8.htm
===================
if(window.location.search) alert(window.location.search)
打开模态窗口
var result = showModalDialog("b2.htm","dialogWidth:270px;dialogHeight:140px;status:'no'"); //显示dialog窗,result变量为此窗返回值数组
从模态窗口返回值
window.returnValue=”aaa” //返回aaa,可直接从表单里获取数据如document.all.textfield.value;
window.close(); //关闭模态窗口
向模态窗口传值
传递
var args = new array();args[0]=”a”; //第一个参数为”a”
args[1]=”b”; //第二个参数为”b”
url="a2.htm";
state="dialogWidth:200px;dialogHeight:100px;status:'no'";
var result = showModalDialog(url, args,state);
窗口中接收
v1=window.dialogArguments[0];
v2=window.dialogArguments[1];
模态窗口中的页面提交问题
在模态窗口中,如有提交按钮,点击后会弹出新的页面。解决此问题有两种方法:
1、在head中,添加注意:不要在form中再添加target="_self" 否则失效
2、把弹出的窗口页面做成框架网页,去加载要展示的网页
如果你的浏览器是IE5.5+,可以在对话框中使用带name属性的iframe,提交时可以制定target为该iframe的name。对于IE4+,你可以用高度为0的frame来作:例子,
test6.htm
===================
window.showModalDialog( "test7.htm ")
test7.htm
===================
if(window.location.search) alert(window.location.search)
test8.htm
===================
if(window.location.search) alert(window.location.search)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/787018/viewspace-712769/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/787018/viewspace-712769/