Java关闭窗口函数,子窗口关闭时的回调函数调用

I have open child window when click on button.In this window I have save some data into database.

I want to call another java script function when child window is close.

I have already tried this Set a callback function to a new window in javascript solution but it is not working.

So please tell me how to call callback function ?

I have also set one hidden field from child window after successfully save.I have try to alert this hidden value but its alert before updating.

function open_child()

{

$("#child_succ").val(0);

alert($("#child_succ").val());

window.open("child.php","Ratting","width=550,height=300,left=150,top=200,toolbar=1,status=1");

alert($("child_succ").val());

}

Callback function

function test()

{

alert("called from child window");

}

解决方案

You may call a parent function from child window this way:

window.opener.your_function()

To call a child function in parent window:

var w = window.open(somelocation,''); //has a function on `window` called "test"

w.test();

If any of this tips help you, you may show us how the callback approach was used by you.

Hope this helps you.

Regards!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
异常处理是Java编程中的重要概念之一,它可以使程序在发生错误进行相应处理,保证程序的健壮性和可靠性。在Java中,异常处理主要通过try-catch-finally语句块实现。 以下是一个示例程序,演示了如何调用方法并回调函数,同处理可能抛出的异常: ```java public class ExceptionHandlingExample { public static void main(String[] args) { try { // 调用方法 int result = divide(10, 0); // 输出结果 System.out.println("Result: " + result); } catch (ArithmeticException e) { // 处理异常 System.out.println("Exception caught: " + e.getMessage()); } finally { // 执行回调函数 callback(); } } // 定义一个方法 public static int divide(int a, int b) throws ArithmeticException { if (b == 0) { throw new ArithmeticException("Division by zero"); } return a / b; } // 定义一个回调函数 public static void callback() { System.out.println("Callback function called"); } } ``` 在上面的示例中,我们定义了一个divide()方法,它接受两个整数参数,如果第二个参数为0,则抛出一个ArithmeticException异常。在main()方法中,我们调用divide()方法并捕获可能抛出的异常。无论是否发生异常,都会执行finally块中的代码,即回调函数callback()。 在实际编程中,我们需要根据具体情况选择合适的异常类型,并编写相应的异常处理代码来保证程序的正常运行。同回调函数也是一种常用的编程技巧,它可以在某个事件发生自动调用指定的函数,从而实现更加灵活的编程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值