Dialog page的若干问题

 

    Dialog page的若干问题

/images/cooleader320/File/Samples/DevSummary.rar

  •  打开 modal dialog pag
Syntax
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
 
Parameters
sURL
Required. String that specifies the URL of the document to load and display.
vArguments
Optional. Variant that specifies the arguments to use when displaying the document. Use this parameter to pass a value of any type, including an array of values. The dialog box can extract the values passed by the caller from the dialogArguments property of the window object.
sFeatures
Optional. String that specifies the window ornaments for the dialog box, using one or more of the following semicolon-delimited values:
dialogHeight:sHeight
Sets the height of the dialog window (see Remarks for default unit of measure).
dialogLeft:sXPos
Sets the left position of the dialog window relative to the upper-left corner of the desktop.
dialogTop:sYPos
Sets the top position of the dialog window relative to the upper-left corner of the desktop.
dialogWidth:sWidth
Sets the width of the dialog window (see Remarks for default unit of measure).
center:{ yes | no | 1 | 0 | on | off }
Specifies whether to center the dialog window within the desktop. The default is yes.
dialogHide:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window is hidden when printing or using print preview. This feature is only available when a dialog box is opened from a trusted application. The default is no.
edge:{ sunken | raised }
Specifies the edge style of the dialog window. The default is raised.
help:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays the context-sensitive Help icon. The default is yes.
resizable:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window has fixed dimensions. The default is no.
scroll:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays scrollbars. The default is yes.
status:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays a status bar. The default is yes for untrusted dialog windows and no for trusted dialog windows.
unadorned:{ yes | no | 1 | 0 | on | off }
Specifies whether the dialog window displays the border window chrome. This feature is only available when a dialog box is opened from a trusted application. The default is no.
Return Value
Variant. Returns the value of the returnValue property as set by the window of the document specified in sURL .
  • 参数传递问题,可以考虑使用下面两种方式交互
         [1]通过window.showModalDialogdialog page 传入参数,通过returnValue 返回值或则任何对象。
          [2]通过window.showModalDialog,把源页面的window对象作为参数传入,在dialog page中通过传入的window对象调用父页面的方法,更新页面。
  • WebDialog postback后引起的问题
       如果打开的模态对话框是aspx页面,页面上有control会导致页面postback的话,回传之后 就会在客户端打开一个新的IE,而不是在那个modalDialog页面上更新,见下图:
  一般可以采取2中方法来避免这个问题:
[1]使用了Iframe,打开的Dialog是一个html的页面,在这个页面里用一个Iframe去请求实际需要的aspx page,代码如下:
   <html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
<iframe width="100%"  height="100%" scrolling="no" src="Dialog2.aspx">
</iframe>

</body>
</html>
这样页面postback后,仍会在原来的Dialog.htm中打开。
[2]给打开的那个aspx页面的HTMLHead部分 添加<base targrt="_self"〉
     回发以后,页面不会在新的IE窗口打开。

HTML4.01/XHTML1.0 关于 base 元素的target属性参考

属性

描述

DTD

target

_blank
_parent
_self
_top

Where to open all the links on the page. This attribute can be overridden by using the target attribute in each link.
页面中所有连接的打开方式。如果每个连接使用了target属性那么basetarget属性就无效了

  • _blank - all the links will open in new windows
    所有的连接将在新窗口打开
  • _self - all the links will open in the same frame they where clicked
    所有的连接将在自身窗口或是框架中打开
  • _parent - all the links will open in the parent frameset
    所有连接在父级框架集中打开
  • _top - all the links will open in the full body of the window
    所有连接在窗口的主体中打开

 

  • Page 打开方式不同,可能导致页面和脚本加载次序不同
       showModalDialog(),showModelessDialog()打开的页面,浏览器 (只试验了IE) 在执行的时候可能是先解释,但并不立即render.相反直接以windwo.open()打开page的时候,则是边解释,边render,一点遇到js脚本则立即执行
    
<html >
<head>
    
<title>new document </title>
</head>
<body>
   
<!-- declaration first-->
    
<input id="txt1" value="just test" style="width: 224px">

    
<script type="text/javascript">
    
<!--
    alert(document.getElementById(
'txt1').offsetWidth);
    
//-->
    
</script>

</body>
</html>

                              showModalDialog()/showModelessDialog()的结果:

           

          

          window.open()的结果

  从IE的运行结果,几乎同时弹出Alert框和dialog page,并且我们得到了预期的正确结果。这说明,这种方式下IE是边解析边render页面的内容

showModalDialog 打开一个 aspx 页面时被缓存导致的问题

         showModalDialog 打开一个 aspx 页面时,如果该页面在之前已经打开过一次,则自动会加载缓存中的页面,而不能显示最新数据

一般有两种解决方法:

      [1]在打开模态框时,给 url 后面多加一个随机参数,来避免页面被缓存

        [2]code behind设定不缓存:    

Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
阅读更多
个人分类: Web 开发
上一篇UML 学习笔记------ 类建模
下一篇Cross page postback
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭