JavaScript 实现模态对话框 源代码大全(4)

showModalDialog 打开的模态对话框有不少经典的缺陷,在这里不再冗述,我只谈谈最近碰到的几个问题以及解决办法。

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

解决的办法有两种:

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

var url = 'EditFlowNode.aspx?flowId=0&id=2&x=' + Math.random();
var result = window.showModalDialog(url, '', 'status:no; help:no;');


(2). 在该 asp.net 页面的 Page_Load 方法里设定不缓存:

protected void Page_Load(object sender, EventArgs e){
    Response.Expires 
= 0;
    Response.Cache.SetNoStore();
    Response.AppendHeader(
"Pragma""no-cache");
}



问题2. 模态对话框中的内容和脚本加载次序不同,导致的问题。

缘起:考虑如下页面的代码

<!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>
  
<title> new document </title>
  
<meta name="generator" content="editplus" />
  
<meta name="author" content="" />
  
<meta name="keywords" content="" />
  
<meta name="description" content="" />
 
</head>

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwxzw.html