`
hudeyong926
  • 浏览: 2028433 次
  • 来自: 武汉
社区版块
存档分类
最新评论

ShowModalDialog与window.open的区别

阅读更多
function goToURL(url,args,self){
	if(self=="0"){			//本页打开
		window.location = url+args;
	}if(self=="1"){		//新页打开
		window.open(url+args);
	}
}

 

<a href="#" onclick="goToURL(XXXX)" id="href1">XXX</a>不能要target="_XXX“,否则js失效


ShowModalDialog函数、改变模态窗口大小

ShowModalDialog函数的功能: 打开一个子窗口,并且可与父窗口相互传递数据,它与window.open的最大区别就在于由ShowModalDialog打开子窗口后,父窗口将不能操作。 使用方法: vReturnValue = window.showModalDialog(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。 参数传递方法: 父窗口向子窗口传递参数采用ShowModalDialog的第2个参数即可,父窗口要获取子窗口传回的参数则可通过ShowModalDialog函数的返回值获取。 子窗口获取父窗口参数的方法为采用子窗口window对象dialogArguments属性获取,例如: var a=window.dialogArguments; 子窗口向父窗口返回参数采用window.returnValue属性,如: window.returnValue=1; window.close();

 

改变模态窗口大小

1.html

< HTML> < HEAD> < TITLE> 改变对话框的大小< /TITLE> < /HEAD> < script> function showdialog(){ window.showModalDialog(" 2.html" ," " ,' edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No; dialogHeight:200px; dialogWidth:300px' ); } < /script> < BODY> < input type=button value=" showdialog" onclick=" showdialog(); " > < /BODY> < /HTML>

2.< HTML> < HEAD> < TITLE> 改变对话框的大小< /TITLE> < /HEAD>

< BODY onload=Resize_dialog(1000,1000,1000,1000)> < SCRIPT LANGUAGE=" JavaScript" > function Resize_dialog(t,l,w,h) { window.dialogTop = t+" px" ; window.dialogLeft = l+" px" ; window.dialogHeight = h+" px" ; window.dialogWidth = w+" px" ; }

< /SCRIPT> < /BODY> < /HTML>

=================================================================================

window.open是打开新窗口 window.showModalDialog(URL,dialogArgments.features) 打开一个新窗口 URL为要开启的网页。 dialogArgments为设定好传递给新视窗网页的参数,可以为任意数据类型。 feature 与open()的类似,都是格式方面的设定。调用格式为featureName1:featureValue1:(分号)featureName2:featureValue2: certer , dialogHeight , dialogLeft ,dialogTop ,dialogWidth ,help (是否显示help按钮,下同),status ,resizeable 值=1为yes,0为no. 我认为最重要的是dialogArgments ,可以传递值到新的窗口。 第二重要就是 它的返回值 window.returnValue.可以在showModalDialog开启的窗口关闭后前,回传一个任意类型的值

参数传递: 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.51js.com"; </script> ====================================================================================

showModalDialog() 弹出一个对话框,对话框是依附于打开它的那个窗口的;window.open() 是开一个新窗口,和打开它的那个窗口是独立的 showModalDialog() 必须关闭才能操作打开它的那个窗口;而 window.open() 打开的窗口不必关闭也可以操作打开它的那个窗口 二者控制打开它的窗口方法也不一样,一个使用 dialogArguments,后者使用 opener

 

<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=no,resizable=no,location=no, status=no')
//写成一行
-->
</SCRIPT>

参数解释:

<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
</SCRIPT> js脚本结束 

 

 

分享到:
评论

相关推荐

    window.showModalDialog以及window.open用法简介

    Window.showModalDialog 和 Window.open 用法简介 Window.showModalDialog 和 Window.open 都是 JavaScript 中的方法,用于创建新窗口或对话框,下面分别介绍它们的用法和参数。 一、Window.open() 方法 Window....

    window.showModalDialog模式对话框和 window.open的区别

    `window.showModalDialog` 和 `window.open` 都是JavaScript提供的两种打开新窗口的方法,但它们在功能和使用场景上有着显著的区别。 首先,我们来详细探讨`window.showModalDialog`。`showModalDialog`方法用于...

    父子窗口传值window.showModalDialog以及window.open用法简介

    window.showModalDialog以及window.open用法简介

    showModalDialog和window.open

    ### showModalDialog和window.open在Web开发中的应用与区别 在Web开发中,`showModalDialog`和`window.open`是两种用于打开新窗口或对话框的方法,但它们各自有着独特的特性和应用场景。以下是对这两种方法的详细...

    js的window.showModalDialog及window.open用法实例分析

    与`window.open`不同的是,`showModalDialog`创建的窗口是不可多任务的,用户必须先处理对话框,才能继续操作原页面。基本使用方法如下: ```javascript vReturnValue = window.showModalDialog(sURL [, vArguments...

    showModalDialog open弹出子窗口操作parent、opener父窗口及跨域处理

    1&gt; window.showModalDialog()采用JS原理实现,同时父窗口不可操作,window.open()采用新创建一个窗口,同时父窗口可操作; 2&gt; 父窗口与子窗口传递值的方式也有所不同,在子窗口中操作父窗口也语法也不同,分别为var...

    Window.ShowModalDialog使用手册

    在JavaScript编程语言中,`Window.showModalDialog()`方法是一个非常重要的功能,主要用于打开一个模态对话框,即用户必须关闭对话框才能与父窗口进行交互。这个方法在创建用户交互和自定义弹出窗口场景中非常有用。...

    window.showModalDialog(javascript)

    【window.showModalDialog() 方法详解】 在Web开发中,JavaScript提供了两种对话框方式来与用户交互,即模态对话框和非模态对话框。本文将重点介绍模态对话框的使用方法`window.showModalDialog()`。 模态对话框是...

    'window.ShowModalDialog'在Chrome中不起作用

    `window.showModalDialog()` 是一个古老的JavaScript方法,用于在当前页面上打开一个模态对话框,该对话框阻止用户与页面其余部分进行交互,直到对话框被关闭。然而,这个功能在现代浏览器,特别是Google Chrome中...

    window.showModalDialog方法的使用

    在JavaScript编程中,`window.showModalDialog`是一个用于打开模态对话框的函数,它能够创建一个新的浏览器窗口或者在当前窗口内显示一个弹出层,阻止用户与父窗口的交互,直到用户关闭对话框为止。这个方法在创建...

    js实现window.open不被拦截的解决方法汇总

    文章中提到了几种实现 `window.open()` 方法不被浏览器拦截的解决方法,其中包括新建 `a` 标签模拟点击、使用 `window.showModalDialog()` 方法和使用 `setTimeout()` 与 `window.open()` 结合的方式。 1. 新建 `a`...

    JS控制弹出页面窗口控件(openWin)

    window.open()和window.showModalDialog(),并解决了showModalDialog()弹出窗口中列表分页的问题。 提供了三个JS方法: (1)showWindow(sURL, width, height); (2)showWindowInPage(pageUrl, params, title, ...

    window.open 函数的操作

    本篇内容详细介绍了 `window.open` 函数的基本用法及其在实际开发中的应用场景,同时探讨了如何从 `showModalDialog` 中获取数据对象的方法,以及 `request.getParameterMap()` 在处理 HTTP 请求参数时的具体使用。...

    window.showModalDialog('d.html',fault,'');

    在这个例子中,`window.showModalDialog` 是用来显示一个模态窗口,用户必须与该窗口交互(关闭它)才能继续在主窗口中操作。我们来详细探讨这个知识点。 `window.showModalDialog` 是一个古老的浏览器内置函数,...

    showModalDialog模态对话框的使用详解以及浏览器兼容

    `showModalDialog`是JavaScript中`window`对象的一个方法,用于打开一个模态对话框,即新打开的窗口会阻止用户与父窗口的交互,直到该对话框被关闭。这与`window.open`方法不同,后者打开的新窗口并不会阻止用户在父...

Global site tag (gtag.js) - Google Analytics