有网页开发时,我们有时需要在一个页面弹出一个dialog1,然后再在dialog1中弹出dialog2,这时如果我们在dialog2有一个关闭按钮将dialog2自身关闭掉,这时会出现一个bug,即dialog2关闭后,浏览器会自动打开一个新的空白页面。这不是我们期望的结果,那我们该如何解决这个问题呢。我个人想到的解决方法有两个:

1)dialog1不用dialog,而是用一个window来模拟,这有点曲线救国的意思。

2)利用iframe来完成。我们新建一个IframeDialog.aspx页面,代码如下:


    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
<title></title>
</head>
<body>
    
<iframe id="frame" style="min-height: 100%; height: 100%; width: 100%; min-width: 100%"
        src
='<%= Request.QueryString["dialogpath"] %>'></iframe>

    
<script type="text/javascript">
        
function resizeIframe() {
            
//如果你没有dtd定义 那么document.documentElement.clientHeight 应该改 为document.body.clientHeight
            var height = document.documentElement.clientHeight;
            height 
-= document.getElementById('frame').offsetTop;

            
// not sure how to get this dynamically
            height -= 20/* whatever you set your body bottom margin/padding to be */

            document.getElementById(
'frame').style.height = height + "px";
        }
    
</script>

    
<script language="javaScript">

        document.getElementById(
'frame').onload = resizeIframe;
        window.onresize 
= resizeIframe;
    
</script>

</body>
</html>

然后我们打开dialog1和dialog2时,改变一下,用window.showModelDialog('IframeDialog.aspx?dialogpath=dialog1/2.aspx');这样的形式来打开,即不是直接打开dialog,而是打开一个iframe页面,在iframe里显示dialog页面。

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2021-12-06
  • 2021-05-24
  • 2021-12-23
  • 2021-12-26
  • 2021-09-23
  • 2022-12-23
相关资源
相似解决方案