关于web对话窗口使用总结

来源:互联网 发布:php砍价源码 编辑:程序博客网 时间:2024/06/09 21:36

 一、对话框一般分为两种类型:模态类型(modal)与非模态类型(modeless)。所谓模态对话框,就是指除非采取有效的关闭手段,用户的鼠标焦点或者输入光标将一直停留在其上的对话框。非模态对话框则不会强制此种特性,用户可以在当前对话框以及其他窗口间进行切换。

二、原型

创建模态对话框:(会缓存最近一次页面的值,通过一些设置可绕过系统的判断)
vReturnValue = window.showModalDialog(sURL [, vFreeArgument] [, sOrnaments]);
创建非模态对话框:(不会)
vReturnValue = window.showModelessDialog(sURL [, vFreeArgument] [, sOrnaments]);

· VReturnValue:对于showModalDialog(),它表示被打开的对话框窗口设置的returnValue属性值。对于showModelessDialog(),它表示新窗口对象。 
· VFreeArgument:这个参数可用于传递某种类型的数据到打开的对话框,数据可以是一个数值、字符串、数组或者一个对象类型。在新窗口中引用这个数值时,可通过新创建window对象的dialogArguments 属性。 
· SOrnaments:用这个参数指定新窗口的外观。可选择的窗口属性有很多种,当有多种控制需求时,将相关内容用一个字符串连接起来,其间用分号隔开。以下是可选择的属性种类: 
o dialogHeight: sHeight 
o dialogLeft: sXpos 
o dialogTop: sYpos 
o dialogWidth: sWidth 
o center: ( yes | no | 1 | 0 | on | off ) 
o dialogHide: ( yes | no | 1 | 0 | on | off ) 
o edge: ( sunken | raised ) 
o help: ( yes | no | 1 | 0 | on | off ) 
o resizable: ( yes | no | 1 | 0 | on | off ) 
o scroll: ( yes | no | 1 | 0 | on | off ) 
o status: ( yes | no | 1 | 0 | on | off ) 

 

三、使用范例

主调页

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>    <title>模态窗口和非模态窗口</title>    <script language="javascript">    var sColor="yyyy";    var sName="xmddl369";    function showModalWindow(){        window.showModalDialog('test2.html',window,'dialogWidth:400px;dialogHeight:400px');    }    function showModellessWindow(){        window.showModelessDialog('test2.html',window,'dialogWidth:400px;dialogHeight:400px;edge:sunken');    }    function update()     {         oColor.innerText = sColor;     }     function test()    {        alert(123);    }    document.write("sColor="+sColor+"<br>");    document.write("sName="+sName+"<br>");    </script></head><body>    <form>    <input type="button" name="button" value="打开一个模态窗口" onclick="showModalWindow()">    <input type="button" name="button" value="打开一个非模态窗口" onclick="showModellessWindow()">    <br>    <p>        输入你最喜欢的颜色: <span id="oColor" style="color: red; font-size: 24">Yellow</span></p>    </form></body></html>


被调页

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head>    <title>New Document </title>    <script language="javascript">    function getInfoAndUpdate() {        var callerWindowObj = dialogArguments; //得到文档的引用        callerWindowObj.sColor = document.all("oEnterColor").value;         callerWindowObj.update();     }    function cancel() {         var callerWindowObj = dialogArguments; //获取父窗口句柄        callerWindowObj.test();//调用父窗口方法        alert(callerWindowObj.sName);//获取父窗口中的变量        callerWindowObj.sColor = "Yellow"; //设置父窗口的变量        callerWindowObj.update();  //调用父窗口方法    }     </script></head><body>    <form>    输入你最喜欢的颜色:<input type="text" name="oEnterColor" id="oEnterColor"><br>    <br>    <input value="Apply" type="button" onclick="getInfoAndUpdate();">    <input value="Ok" type="button" onclick="getInfoAndUpdate();window.close();">    <input value="Cancel" type="button" onclick="cancel();window.close();">    </form></body></html>

原创粉丝点击