zoukankan      html  css  js  c++  java
  • 页面弹出窗口刷新父页面方式小结

       一个页面上弹出子窗常用的方法有两种:1.window.open()方式。2.window.showModalDialog()方式。两种弹出方式刷新父页面的方式也不一样。下面简单介绍一下:

         window.open(pageURL,name,parameters) 方式打开:

    Js代码
    1. window.open('b.html','window',"height=400,width=400,top=300,left=400,toolbar=1,menubar=1,scrollbars=no,resizable=yes,location=yes,status=1");  
    window.open('b.html','window',"height=400,width=400,top=300,left=400,toolbar=1,menubar=1,scrollbars=no,resizable=yes,location=yes,status=1");

       在b.html弹出页面上可用以下方式刷新父页面或调用父页面上的JS方法并且关闭b.html:

    Js代码
    1. function closeReflush(){  
    2.     //window.opener.location.reload();  
    3.     window.opener.reloadparent();//reloadparent父页面的js方法  
    4.     self.close();//关闭子页面  
    5. }  
    function closeReflush(){//window.opener.location.reload();window.opener.reloadparent();//reloadparent父页面的js方法self.close();//关闭子页面}

       window.showModalDialog(pageURL,name,paramenters)方式打开刷新父页面方式多种:

       方式一:

       在父页面上调用代码:

    Js代码
    1. function showDialog(){  
    2.         var returnVal=window.showModalDialog('c.html','window','resizable:yes;scroll:yes;status:yes;dialogWidth=400px;dialogHeight=400px;center=yes;help=no');  
    3. if(!returnVal)return;  
    4. //window.location.reload();  
    5. window.reloadparent();    
    6. }  
     function showDialog(){         var returnVal=window.showModalDialog('c.html','window','resizable:yes;scroll:yes;status:yes;dialogWidth=400px;dialogHeight=400px;center=yes;help=no');if(!returnVal)return;//window.location.reload();window.reloadparent(); }

      通过showModalDialog的返回值判断是否要刷新父页面或调用父页面的JS。在子页面传递给父页面返回值:

    Js代码
    1. function closeReflush(){  
    2.     //do something...  
    3.     window.returnValue="ok";  
    4.     self.close();  
    5.  }  
    function closeReflush(){//do something...    window.returnValue="ok";self.close(); }

     备注:判断子页面是关闭还是刷新(IE7还没测试) 。

    Js代码
    1. window.onbeforeunload=function(){     
    2.              var n = window.event.screenX - window.screenLeft;      
    3.               var b = n > document.documentElement.scrollWidth-20;      
    4.               if(b && window.event.clientY < 0 || window.event.altKey){                      alert("是关闭而非刷新");    
    5.                      //window.event.returnValue="ok";  
    6.                      window.returnValue = "ok"//这里可以放置你想做的操作代码      
    7.   
    8.               } else{  
    9.                     alert("是刷新而非关闭");     
    10.                  }     
    11.   
    12.    }     
    window.onbeforeunload=function(){                var n = window.event.screenX - window.screenLeft;                  var b = n > document.documentElement.scrollWidth-20;                  if(b && window.event.clientY < 0 || window.event.altKey){                      alert("是关闭而非刷新");                       //window.event.returnValue="ok";                     window.returnValue = "ok"; //这里可以放置你想做的操作代码                  } else{                    alert("是刷新而非关闭");                    }      }   
  • 相关阅读:
    20145334赵文豪《网络对抗》 后门原理与实践
    20145334赵文豪《网络对抗》-逆向及Bof基础实践
    20145333茹翔《网络对抗》Exp9 Web安全基础实践
    20145333茹翔 Exp8 Web基础
    20145333茹翔 Exp7 网络欺诈技术防范
    20145333茹翔《网络对抗技术》Exp6 信息搜集技术
    20145333茹翔 Exp5 MSF基础应用
    20145333茹翔 Exp5 利用nmap扫描
    20145333茹翔 Exp5 Adobe阅读器漏洞攻击
    20145333茹翔 Exp5 MS11_050
  • 原文地址:https://www.cnblogs.com/anmoon/p/1792233.html
Copyright © 2011-2022 走看看