window.returnValue

returnValue是javascript中html的window对象的属性,目的是返回窗口值,当用window.showModalDialog函数打开一个IE的模式窗口(模式窗口知道吧,就是打开后不能操做父窗口,只能等模式窗口关闭时才能操做)时,用于返回窗口的值,下面举个例子:javascript

一、parent.htmlhtml

//father.html
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="javascript">

function showmodal(){
var ret = window.showModalDialog("child.htm",null,"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
    if (ret){alert('子窗口返回真!');
    }else{
         alert('子窗口返回假!');
   }
}
</script>
</HEAD>

<BODY>
<INPUT id=button1 type=button value=Button name=button1 onclick="showmodal();">
</BODY>
</HTML>

  

二、child.htmljava

//child.html
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="javascript">
function trans(tag){
   if (tag==0){
       window.returnValue=false;
   } else{
       window.returnValue =true;
  }
   window.close();
}
</script>
</HEAD>
<BODY>

<INPUT id=button1 type=button value="返回真" name=button1 onclick="trans(1)">
<INPUT id=button2 type=button value="返回假" name=button2 onclick="trans(0)">

</BODY>
</HTML>

另:页面禁用右键例子数组

  oncontextmenu=self.event.returnValue=false函数

  说明:htm

  oncontextmenu= 当单圾右键打开菜单时触发事件
  self 得到当前窗口的引用
  event.returnValue=false 设置事件的返回值为false,即取消事件处理对象

 

总结:blog

       这样一来能够实现从模式窗口向父窗口传递值的做用,这个returnValue除了能够是布尔值,整型值等之外还能够是个js数组,用来传递大量数据。事件

 

        具体showModalDialog等的用法,能够参考msdn。ip

相关文章
相关标签/搜索