模态窗口和非模态窗口11

来源:百度文库 编辑:神马文学网 时间:2024/07/03 08:18:34
对话框一般分为两种类型:模态类型(modal)与非模态类型(modeless)。所谓模态对话框,就是指除非采取有效的关闭手段,用户的鼠标焦点或者输入光标将一直停留在其上的对话框。非模态对话框则不会强制此种特性,用户可以在当前对话框以及其他窗口间进行切换。本文介绍如何使用JavaScript语言来创建这两种类型的对话框、控制其大小和位置、改变其外观以及在对话框间的数据传递。(引用)
一、创建模态和非模态对话框

创建模态对话框:(会缓存最近一次页面的值,通过一些设置可绕过系统的判断)
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 ) 

二、控制对话框大小和位置

三、改变对话框外观
 
四、从Noname1.html页面传递数据到Noname2.html页面

传递对象类型数据




模态窗口和非模态窗口

 var sColor="yyyy";
 var sName="xmddl369";
 function showModalWindow(){
   window.showModalDialog(‘Noname2.html‘,window,‘dialogWidth:400px;dialogHeight:400px‘);
 }
 function showModellessWindow(){
  window.showModelessDialog(‘Noname2.html‘,window,‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
 }
 function update() 
 
  oColor.innerText = sColor; 
 } 
 document.write("sColor="+sColor+"
");
 document.write("sName="+sName+"
");









输入你最喜欢的颜色: Yellow





-------------------




 New Document 

function getInfoAndUpdate() {
 var callerWindowObj = dialogArguments; //得到文档的引用
 callerWindowObj.sColor = document.all("oEnterColor").value; 
 callerWindowObj.update(); 
 }
function cancel() 
 var callerWindowObj = dialogArguments; 
 callerWindowObj.sColor = "Yellow"; 
 callerWindowObj.update();  





输入你最喜欢的颜色:

 
 
 
 



传递数组引用类型数据




模态窗口和非模态窗口

 var fruit=new Array();
 fruit[0]="苹果";
 fruit[1]="桔子";
 fruit[2]="梨";
 fruit[3]="香蕉";
 function showModalWindow(){
   window.showModalDialog(‘Noname2.html‘,fruit,‘dialogWidth:400px;dialogHeight:400px‘);
 }
 function showModellessWindow(){
  window.showModelessDialog(‘Noname2.html‘,fruit,‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
 }













------------------




 New Document 

function deWrite(){
 var myobject=document.getElementById("ifruit");
 var myfruit=dialogArguments;

 for(count=0;count{
  var oOption = document.createElement("OPTION");
  oOption.text=myfruit[count];
  oOption.value=/count;
  myobject.add(oOption);
 }
}






增加水果:




传递值类型数据




模态窗口和非模态窗口

 function showModalWindow(){
   window.showModalDialog(‘Noname2.html‘,"xmddl",‘dialogWidth:400px;dialogHeight:400px‘);
 }
 function showModellessWindow(){
  window.showModelessDialog(‘Noname2.html‘,"xmddl369",‘dialogWidth:400px;dialogHeight:400px;edge:sunken‘);
 }













------------------




 New Document 

function deWrite(){
 var names=dialogArguments;//
 document.write(names);
}







其中window.Open(url,,)的一点体会



 New Document 

 function showOpenWindow(){
  window.open(‘http://www.sohu.com‘,‘xmddl‘,‘height=600px,width=800px,toolbar=no,menubar=no,resizable=yes, scrollbars=yes, location=no, status=no‘);
 }





 


//在Url的地方可以跟上一个.do的请求,基于struts架构时可以链接到某一个具体的页面,体现了窗口作为显示的作用
 
   //在模态窗口打开新窗口
在模态窗口的head部分添加如下代码