问题0:showModalDialog和showModelessDialog有什么不同?
这个也许不算问题
--------------------------------------------------------------------------------
一、缓存问题:
首先搞清楚是服务器端的还是客户端的缓存,忌讳“理所当然” ,生活中好多事情都是似是而非,见刘未鹏的 为什么我们这么容易受骗。
方法1:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// server cache side forbidden
2
Response.Expires = 0;
3
Response.Cache.SetNoStore();
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
// client cache side fobidden
6
Response.AppendHeader("Pragma", "no-cache");
7![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
方法2: 重载模态窗口页面基类的OnInit()方法:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
OnInit(EventArgs e)
1
protected override void OnInit(EventArgs e)
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
3
System.Threading.Thread.CurrentThread.CurrentCulture=System.Globalization.CultureInfo.CreateSpecificCulture("zh-CN");
4
Response.Buffer=ture;
5
Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
6
Response.Expires=0;
7
Response.CacheControl="no-cache";
8
string style="<link rel=\"stylesheet\" href=\""+CSSName+"\">\n"; //CSSName是另一个变量,保存Css的地址
9
style+="<base target=\"_self\">\n";
10
Response.Write(style);
11
string nocache="<meta http-equiv=\"pragma\" content=\"no-cache,must-revalidate\">\n";
12
nocache+="<meta http-equiv=\"expires\" content=\"WED,26 Feb 1001 01:01:01 GMT\">\n";
13
Response.Write(nocache);
14
this.Load+=new System.EventHandler(this.BasePage_Load);
15
}
注:代码引自 When Compromise Is not An Option ;
这样避免了在模态窗口页面上的重复操作。
-------------------------------------------------------------------------------
二、参数传递:
window.showModalDialog("filename.htm",var_name)----传递var_name变量,只能传一个参数;但是可以通过window.dialogArguments.form1和window.dialogArguments.var_name="oyiboy"来设置var_name变量,算是一个变通的方法,有了这个变通,就可以做很多事情了,比如 操作父窗口上所有的对象,
比如:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
模态窗口互访
1
主文件的部份js代码。
2
var s1=showModelessDialog('控制.htm',window,"dialogTop:1px;dialogLeft:1px") //打开控制窗口
3
var s2=showModelessDialog('about:blank',window,"dialogTop:200px;dialogLeft:300px") //打开被控制窗口
4![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
控制.htm的部份代码。
6
<script>
7
//操作位置数据,因为窗口的位置数据是"xxxpx"方式的,所以需要这样的一个特殊操作函数。
8
function countNumber(A_strNumber,A_strWhatdo)
9![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
10
A_strNumber=A_strNumber.replace('px','')
11
A_strNumber-=0
12
switch(A_strWhatdo)
13![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
14
case "-":A_strNumber-=10;break;
15
case "+":A_strNumber+=10;break;
16
}
17
return A_strNumber + "px"
18
}
19
</script>
20
<input type="button" onclick="window.dialogArguments.s2.dialogTop=countNumber(window.dialogArguments.s2.dialogTop,'-')" value="上移">
21
<input type="button" onclick="window.dialogArguments.s2.dialogLeft=countNumber(window.dialogArguments.s2.dialogLeft,'-')" value="左移">
22
<input type="button" onclick="window.dialogArguments.s2.dialogLeft=countNumber(window.dialogArguments.s2.dialogLeft,'+')" value="右移">
23
<input type="button" onclick="window.dialogArguments.s2.dialogTop=countNumber(window.dialogArguments.s2.dialogTop,'+')" value="下移">
24![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
以上关键部份是:
26
窗口命名方式:var s1=showModelessDialog('控制.htm',window,"dialogTop:1px;dialogLeft:1px")
27
变量访问方式:window.dialogArguments.s2.dialogTop
就此打住!