`

windows.showdialog()

阅读更多

 Javascript有许多内建的方法来产生对话框,如:window.alert(), window.confirm(),window.prompt().等。 然而IE提供更多的方法支持对话框。如: 

    showModalDialog() (IE 4+ 支持)
   showModelessDialog() (IE 5+ 支持)

    window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框,由于是对话框,因此它并没有一般用window.open()打开的窗口的所有属性。

    window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。 

    当我们用showModelessDialog()打开窗口时,不必用window.close()去关闭它,当以非模态方式[IE5]打开时, 打开对话框的窗口仍可以进行其他的操作,即对话框不总是最上面的焦点,当打开它的窗口URL改变时,它自动关闭。而模态[IE4]方式的对话框始终有焦点(焦点不可移走,直到它关闭)。模态对话框和打开它的窗口相联系,因此我们打开另外的窗口时,他们的链接关系依然保存,并且隐藏在活动窗口的下面。

使用方法如下:
   vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
    vReturnValue = window.showModelessDialog(sURL [, vArguments] [, sFeatures])

参数说明:
    sURL
   必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
    vArguments
   可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
    sFeatures
   可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
    dialogHeight 对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
   dialogWidth: 对话框宽度。
   dialogLeft: 距离桌面左的距离。
   dialogTop: 离桌面上的距离。
   center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
   help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
   resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
   status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
    scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。

还有几个属性是用在HTA中的,在一般的网页中一般不使用。
    dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
    edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
    unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。

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

test1.htm
<script>
  var mxh1 = new Array("mxh","net_lover","孟子E章")
  var mxh2 = window.open("about:blank","window_mxh")
  // 向对话框传递数组
  window.showModalDialog("test2.htm",mxh1)
  // 向对话框传递window对象
  window.showModalDialog("test3.htm",mxh2)
</script>test2.htm
<script>
  var a = window.dialogArguments
  alert("您传递的参数为:" + a)
</script> 
test3.htm
<script>
  var a = window.dialogArguments
  alert("您传递的参数为window对象,名称:" + a.name)
 </script>
 可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:

test4.htm
<script>
  var a = window.showModalDialog("test5.htm")
  for(i=0;i<a.length;i++) alert(a[i])
</script>test5.htm
 <script>
 function sendTo()
 {
  var a=new Array("a","b")
  window.returnValue = a
  window.close()
 }
 </script>
 <body>
 <form>
  <input value="返回" type=button onclick="sendTo()">
 </form>
常见问题:
1,如何在模态对话框中进行提交而不新开窗口?
   如果你 的 浏览器是IE5.5+,可以在对话框中使用带name属性的iframe,提交时可以制定target为该iframe的name。对于IE4+,你可以用高度为0的frame来作。例如:

 test6.htm
<script>
  window.showModalDialog("test7.htm")
 </script> test7.htm
if(window.location.search) alert(window.location.search)
 <frameset rows="0,*">
  <frame src="about:blank">
  <frame src="test8.htm">
 </frameset> test8.htm
<form target="_self" method="get">
 <input name=txt value="test">
 <input type=submit>
 </form>
 <script>
 if(window.location.search) alert(window.location.search)
 </script>

分享到:
评论

相关推荐

    将彩色图片转换为灰度图片程序(C#源代码编写)if(this.openFileDialog1.ShowDialog()==DialogResult.OK)

    将彩色图片转换为灰度图片程序(C#源代码编写)if(this.openFileDialog1.ShowDialog()==DialogResult.OK) { bmp=new Bitmap(this.openFileDialog1.FileName); for (int i=0;i&lt;bmp.Width-1;i++) { ...

    记事本 用b.net

    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then rtBook.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If Else '若该文件已存在,则弹出对话框,用户选择...

    C#+sql宿舍管理系统

    main.ShowDialog(); } else MessageBox.Show("用户名或密码错误","警告"); } oleConnection1.Close(); } private void btClose_Click(object sender, System.EventArgs e) { ...

    自定义对话框Messagebox运用dll程序

    将以下字符复印粘贴到文本上 Windows Registry Editor Version 5.00 ...@="C:\\Windows\\MyAssemblies" ...if NewMessagebox.showdialog()=windows.forms.dialogresult.yes then '执行程序 else '退出不执行 end if

    项目_网吧收费系统主程序

    using System.Windows.Forms; using System.Data.SqlClient; using System.Timers; //Download by http://www.codefans.net namespace qwe { public partial class F_main : Form { //定义SqlDataAdapter的引用 ...

    VB.NET将任意图像文件设置为鼠标形状

    If fd.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim fn As Image = Image.FromFile(fd.FileName) Dim bitmap As New Bitmap(fn) Dim handle As IntPtr = bitmap.GetHicon() Dim myCursor As New ...

    删除多个图片的多余透明度区域.zip

    if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Tools.Export(new List(open.FileNames), "D://output"); } this.toolStripStatusLabel1.Text = "图片压缩完成"; } private void button2...

    C#Windows视屏播放器

    C#windows实训题, private void Mp3size() { //获得文件大小 try { FileInfo MyFileInfo = new FileInfo(this.listBoxPlayer.SelectedItem.ToString()); float MyFileSize = (float)MyFileInfo.Length / ...

    silverlight子窗体可缩放效果

    使用教程如下: 1、下载应用dll文件 2、增加一个子页面 2.1、子页面的xaml中的需要更改: 原来: &lt;controls:ChildWindow x:Class="Abs.IBR.PI.Project.Examiner" …… ... extest.ShowDialog(); }

    上传图片代码

    if(opfd.ShowDialog()==System.Windows.Forms.DialogResult.OK) { MemoryStream ms = new MemoryStream(); Image img = Image.FromFile&#40;opfd.FileName&#41;; img.Save(ms, System.Drawing.Imaging.Image...

    C# 俄罗斯方块游戏

    using System.Windows.Forms; using System.Xml; using System.IO; using System.Security.Cryptography; using System.Text; using System.Runtime.Serialization.Formatters.Binary; namespace RussiaBlock { ...

    无线条码打印机源代码

    if(openFileDialog1.ShowDialog() == DialogResult.OK) { if (openFileDialog1.FileName!="") { byte[] OutBuffer; FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess...

    C#对EXCEL表的操作

    windows窗体上放了一个Textbox1,2个按钮button1和button2~按button1选择excel文件~按button2进行相关处理 Code Snippet private void button1_click(object sendeer,EventArgs e) { OpenFileDialog ...

    通过委托实现窗体间通信

    using System.Windows.Forms; namespace Form1DelegateForm2 { /// /// 主窗体 /// public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox1.Text = "演示文本"; } ...

    winForm中主窗体Form获取弹出窗体的中值

    WinForm 是一个基于 Windows Forms 的应用程序框架,用于构建 Windows 桌面应用程序。在 WinForm 中,窗体(Form)是应用程序的基本组成部分,用于显示和交互用户界面。弹出窗体是 WinForm 中一种常用的交互方式,...

    VB课程设计.doc

    Inherits System.Windows.Forms.Form Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AxShockwaveFlash1.Movie = "E:\实验运行场\VB.NET程序设计\系统\...

    基于Window mobile 6 程序设计——文本编辑器

    if (OpenFile.ShowDialog()==System.Windows.Forms.DialogResult.OK&&OpenFile;.FileName.Length&gt;0) { StreamReader din = File.OpenText(OpenFile.FileName); String str; while ((str=din.ReadLine())!=null)...

    API精灵源码(C#编)

    this.mysearch.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mysearch_MouseDown); this.mysearch.TextChanged += new System.EventHandler(this.mysearch_TextChanged); // // ...

    Flash播放器 VB NET代码编写.rar

    VB.NET编写的Flash播放器,虽然现在Flash不那么流行了,这就是HTML5惹的祸,不过通过本源码,你会了解到如何借助Windows的一些DLL,来播放Flash的SWF动画文件,比如获取当前的播放进度,获取当前进度的百分比,设置...

    asp.net调用系统设置字体文本框的方法

    本文实例展示了asp.net调用系统设置字体文本框的方法,是进行web开发中很...fd.ShowDialog().ToString(); 就可以调出系统设置字体的那个文本框了。 二、用FontDialog弹出的文本框设置字体样式和大小 FontDialog fd

Global site tag (gtag.js) - Google Analytics