zoukankan      html  css  js  c++  java
  • JS实现 子窗体关闭,父窗体刷新页面;

    1.窗口关闭事件

    javascript捕获窗口关闭事件有两种方法 onbeforeunload()  ,onUnload()

    <body onUnload="myClose();">
    function
    myClose() { // 可能存在frame页面,所以要引用top窗口. var win = top.window; try { // 刷新. if (win.opener) win.opener.location.reload(); } catch (ex) { // 防止opener被关闭时代码异常。
     }
    }

    2.子父窗体间js调用

    1>父窗体是使用window.open(url,name,feather)打开子窗体时,使用下面的方法获取。
    调用父窗体函数:window.opener.Fun();
    调用父窗体物件:window.opener.document.getElementById("txt_test").value


    2>子窗体是IFrame的时候,直接用window.parent.Fun或window.parent.Obj


    3>父窗体是使用window.showModalDialog(url,arguments,feather)打开子窗体时,使用下面的方法获取。
        (1)体在Show子窗体的时候,把当前window对象(只要对象的话用window.document即可)当参数传到子窗体:
          方法如:window.showModalDialog(url,window,"dialogwidth=300px;")
        (2)窗体获取这个window对象.var pWin=window.dialogArguments;
        (3)同过pWin来调用父窗体函数。(例如 父窗体函数为pFun()); 
     

    var pwin = window.dialogArguments;
    if(pwin!=undefined){
    var codeStr = "pFun();"
    pwin.execScript(codeStr,"javascript");

    上面的方法直接等价于pWin.pFun()

    为易维护、易扩展、易复用、灵活多样而努力~~
  • 相关阅读:
    try-catch 回滚事务,避免回滚失效的操作
    Java 7中的Try-with-resources
    Linux开发环境之配置静态IP地址
    Windows和Linux系统如何退出python命令行
    Python基础(一)
    Linux开发环境之nginx
    Linux开发环境之安装自带jdk
    Linux删除命令的几种方式
    MySQL之新建索引原则
    webapp环境搭建(一)
  • 原文地址:https://www.cnblogs.com/SpringDays/p/3129856.html
Copyright © 2011-2022 走看看