showModalDialog使用例子,父窗口向子窗口传递值,子窗口设置父窗口的值,子窗口关闭的时候返回值到父窗口.

farther.html
---------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
<!--
function openChild(){

var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
if(k != null)
document.getElementById("txt11").value = k;
}
//-->
</script>
</HEAD>

<BODY>
<br>传递到父窗口的值:<input id="txt9" type="text" value="3333333333333"><br>
返回的值:<input id="txt11" type="text"><br>
子窗口设置的值:<input id="txt10" type="text"><br>

<input type ="button" value="openChild" onclick="openChild()">
</BODY>
</HTML>
---------------------------------------------------------------
child.html
--------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

</HEAD>

<BODY>
<br>父窗口传递来的值:<input id="txt0" type="text"><br>
输入要设置父窗口的值:<input id="txt1" type="text"><input type ="button" value="设置父窗口的值" onclick="setFather()"><br>
输入返回的值:<input id="txt2" type="text"><input type ="button" value="关闭切返回值" onclick="retrunValue()">
<input type ="button" value="关闭刷新父窗口" onclick="">

</BODY>
</HTML>

<script language=javascript>
<!--
var k=window.dialogArguments;
//获得父窗口传递来的值
if(k!=null)
 {
 document.getElementById("txt0").value = k.document.getElementById("txt9").value;
 }
 //设置父窗口的值
function setFather()
{
 k.document.getElementById("txt10").value = document.getElementById("txt1").value
}
//设置返回到父窗口的值
function retrunValue()
{
var s = document.getElementById("txt2").value;
window.returnValue=s;
window.close();
}
//-->
</script>

----------------------------
说明:
由于showModalDialog缓存严重,下面是在子窗口取消客户端缓存的设置.也可以在服务器端取消缓存,参考:
http://adandelion.cnblogs.com/articles/252137.html
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
------------------------------------------------------------------------------------------------------------------------
(二)下面是关闭刷新父窗口的例子

farther.html
---------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
<!--
function openChild()
{

var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
 if(k == 1)//判断是否刷新
 {
  alert('刷新');
  window.location.reload();
 }
}
//-->
</script>
</HEAD>

<BODY>
<br>传递到父窗口的值:<input id="txt9" type="text" value="3333333333333"><br>
<input type ="button" value="openChild" onclick="openChild()">
</BODY>
</HTML>
----------------------------------------------------
child.html
--------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">

</HEAD>

<BODY>
<br>父窗口传递来的值:<input id="txt0" type="text"><br>

<input type ="button" value="关闭刷新父窗口" onclick="winClose(1)">
<input type ="button" value="关闭不刷新父窗口" onclick="winClose(0)">

</BODY>
</HTML>

<script language=javascript>
<!--
var k=window.dialogArguments;
//获得父窗口传递来的值
if(k!=null)
 {
 document.getElementById("txt0").value = k.document.getElementById("txt9").value;
 }

//关闭窗口返回是否刷新的参数.
function winClose(isRefrash)
{

window.returnValue=isRefrash;
window.close();
}
//-->
</script>

--------------------------
说明
1.下面是取消客户端缓存的:
<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
也可以在服务器端取消缓存,参考:
http://adandelion.cnblogs.com/articles/252137.html

2.向父窗口传递阐述在ASP.NET中也可以是用aaa.aspx?id=1的方式传递.

3.不刷新父窗口的话在父窗口中直接这样一来设置可以.
<script>
window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px");
</script>
4.在子窗口中若要提交页面的话要加入:,这样就不会打开新窗口了.
<head>
<base target="_self">
</HEAD>

注:

父窗体向子窗体传值还可以这样:

window.showModalDialog("child.html?id=value1&id2=value2&......等",window,"dialogWidth:335px;status:no;dialogHeight:300px");

在子页面中用Request.QueryString["id"]来获取传值。

showModalDialog-父窗体子窗体的更多相关文章

  1. C# WinForm 父窗体 子窗体 传值

    C# WinForm 父窗体 子窗体 传值 本次示例效果如下:Form1为父窗体(包含textBox1.button1)Form2为子窗体(包含textBox2.button2) 父窗体给子窗体传值= ...

  2. c#在主窗体panel 容器内嵌入另一个窗体(子窗体)的实现

    主窗体:  子窗体: 把子窗体嵌入到主窗体的panel 右侧中: 代码: { public MainForm() { InitializeComponent(); } private void Clo ...

  3. (转载)c# winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值

    第一种方法: 用委托,Form2和Form3是同一组 Form2 C#代码 using System; using System.Collections.Generic; using System.C ...

  4. [转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值

    转自:http://heisetoufa.iteye.com/blog/382684 第一种方法: 用委托,Form2和Form3是同一组 Form2  using System; using Sys ...

  5. C#键盘事件处理父窗体子窗体

    :                             :                             MessageBox.Show(, , Keys.F1);            ...

  6. Delphi MDI程序 父窗体如何调用当前活动子窗体的函数/过程

    一个MDI文本文件编辑器打开了N个子窗体子窗体的.pas文件有一些public的过程和函数我想在父窗体调用当前活动的子窗体函数我用Self.ActiveChildForm无法调用直接frmEdit.x ...

  7. Winfrom子窗体刷新父窗体

    本人比较懒,直接从网上转载了一篇比较合适的文章,只是文章格式有点乱,地址是 http://aspnet.blog.163.com/blog/static/17515510920121126104433 ...

  8. Winform子窗体刷新父窗体

    调用窗体(父):Form1,被调用窗体(子):Form2方法1:   所有权法//Form1://需要有一个公共的刷新方法public   void   Refresh_Method(){//...} ...

  9. 20150812 Asp.net 父窗体获取子窗体的返回值,更新父窗体文本控件(应用)

    1. 父窗体 **************************************** using System;using System.Collections;using System.C ...

随机推荐

  1. BZOJ1627: [Usaco2007 Dec]穿越泥地

    1627: [Usaco2007 Dec]穿越泥地 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 478  Solved: 303[Submit][Sta ...

  2. topcoder13185 TreePuzzle

    https://community.topcoder.com/stat?c=problem_statement&pm=13185 被wck屠了. 考试时候想分类讨论,结果发现情况有点复杂,最后 ...

  3. 构建你的第一个App

    Building Your First App 原文链接:http://developer.android.com/training/basics/firstapp/index.html 译文链接1: ...

  4. 我是企业号体验账户 我发送消息:微信错误 errcode=60011,

    http://qydev.weixin.qq.com/qa/index.php?qa=3197&qa_1=%E6%88%91%E6%98%AF%E4%BC%81%E4%B8%9A%E5%8F% ...

  5. Android新浪微博客户端(七)——ListView中的图片异步加载、缓存

    原文出自:方杰|http://fangjie.info/?p=193转载请注明出处 最终效果演示:http://fangjie.sinaapp.com/?page_id=54 该项目代码已经放到git ...

  6. DLL入门浅析(1)——如何建立DLL

    转载自:http://www.cppblog.com/suiaiguo/archive/2009/07/20/90619.html 初学DLL,结合教程,总结一下自己的所得,希望对DLL初学者们有所帮 ...

  7. Java学习日记-7 抽象类和接口

    一.抽象类 abstract修饰:类和类中的方法 抽象方法:abstract type name(parameter-list);(abstract不能修饰static方法和构造函数) 引用:抽象类有 ...

  8. Google 2013 campus test-R1

    Reading Phone Number #include<iostream> #include<fstream> #include<vector> #includ ...

  9. Iterator荟萃

    package com.starain.Iterator;/*代码整理快捷键为Ctrl+Shift+F * main方法输入快捷键main字符+Alt+/ * 输出快捷键sysout字符+Alt+/* ...

  10. 定时执行程序-Quartz简单实例

    1.加jar包:Quartz自己quartz-1.8.3.jar和依赖包commons-logging.jar  .slf4j-log4j12-1.5.10.jar .slf4j-api-1.5.10 ...