您的位置:首页 > 其它

Window.ShowModalDialog使用手册

2010-01-04 10:09 429 查看
Window.ShowModalDialog使用手册

基本介绍:
  showModalDialog() (IE 4+ 支持)
  showModelessDialog() (IE 5+ 支持)
  window.showModalDialog() 方法用来创建一个显示HTML内容的模态对话框。
  window.showModelessDialog() 方法用来创建一个显示HTML内容的非模态对话框。

  使用方法:

  vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
  vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])

  参数说明:

  sURL -- 必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
  vArguments -- 可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
  sFeatures -- 可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。

----------------
1. dialogHeight: 对话框高度,不小于100px
2. dialogWidth: 对话框宽度。
3. dialogLeft: 离屏幕左的距离。
4. dialogTop: 离屏幕上的距离。
5. center: { yes | no | 1 | 0 } : 是否居中,默认yes,但仍可以指定高度和宽度。
6. help: {yes | no | 1 | 0 }: 是否显示帮助按钮,默认yes。
7. resizable: {yes | no | 1 | 0 } [IE5+]: 是否可被改变大小。默认no。
8. status:{yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
9. scroll:{ yes | no | 1 | 0 | on | off }:是否显示滚动条。默认为yes。

下面几个属性是用在HTA中的,在一般的网页中一般不使用。

10. dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
11. edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
12. unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

  参数传递:

1.要想对话框传递参数,是通过vArguments来进行传递的。类型不限制,对于字符串类型,最大为4096个字符。也可以传递对象,例如

parent.htm

<script>
  var obj = new Object();
  obj.name="51js";
  window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
  var obj = window.dialogArguments
  alert("您传递的参数为:" + obj.name)
</script>

-------------------------------
2. 可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------
parent.htm
<script>
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script>
window.returnValue="http://www.webjx.com/";
</script>

工作使用总结:

sUrl:如跳出的对话框公共调用,放在一个文件夹下public,那sUrl="Public/web.aspx".

1.第一个页面

1.1.html代码

“var num=Math.random();”加个随机行数,让跳出的窗口更新。

// window.location.reload(); '刷新出现错误“新整理网页,必须重新传送资讯”用以下代替,就会解决此问题。
window.location.href=window.location.href;

Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
// <!CDATA[

function btnShowModalDialog_onclick() {

var V1="Hello,";
var V2="ike_li";
var num=Math.random();
var sret=window.showModalDialog("Default2.aspx?V1="+V1+"&V2="+V2+"&num="+num,"","dialogHeight: 655px; dialogWidth: 759px; dialogTop: 60px; dialogLeft: 100px; edge: Raised; center: Yes;help:no; resizable: Yes; status: Yes;scroll:no;")
if(sret == "refresh")
{
window.location.href=window.location.href;
}

}

// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="btnShowModalDialog" style="width: 216px" type="button" value="TestShowModalDialog" onclick="return btnShowModalDialog_onclick()" /></div>
</form>
</body>
</html>

2.跳出窗口

2.1 html代码

“<base target="download"/> ,<iframe id="download" name="download" height="0px" width="0px"></iframe>” 为了防止点击button,处理数据,保持原页面的大小,也可以换成“ <base target="_self" />”,但这个在处理下载文件另存会出现没有反应。

Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Dialog Page</title>
<base target="download"/>

<script language="javascript" type="text/javascript">
// <!CDATA[
function closed()
{
window.returnValue = "refresh";

}
// ]]>
</script>
</head>
<body onunload="closed()">
<form id="form1" runat="server">
<iframe id="download" name="download" height="0px" width="0px"></iframe>
<div>
<asp:Button ID="Button1" runat="server" Height="32px" Text="Button" Width="72px" />
<asp:Label ID="lblShow" runat="server" Width="96px"></asp:Label></div>
</form>
</body>
</html>

2.2后台代码

Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str1 = Request.QueryString["V1"];
string str2 = Request.QueryString["V2"];
lblShow.Text = str1 + str2;
}
}

Javascript刷新页面的几种方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href

自动刷新页面的方法:
1.页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面.

2.页面自动跳转:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">
其中20指隔20秒后跳转到http://www.wyxg.com/页面

3.页面自动刷新js版
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>

ASP.NET如何输出刷新父窗口脚本语句
1. this.response.write("<script>opener.location.reload();</script>");

2. this.response.write("<script>opener.window.location.href = opener.window.location.href;</script>");

3. Response.Write("<script language=javascript>opener.window.navigate(''你要刷新的页.asp'');</script>")

JS刷新框架的脚本语句

//如何刷新包含该框架的页面用
<script language=JavaScript>
parent.location.reload();
</script>

//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )

//如何刷新另一个框架的页面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>

如果想关闭窗口时刷新或者想开窗时刷新的话,在<body>中调用以下语句即可。

<body onload="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新

<script language="javascript">
window.opener.document.location.reload()
</script>

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xue_feitian/archive/2009/11/27/4886496.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: