关闭子窗口 并 刷新父窗口

本文介绍了一段用于在浏览器中关闭当前窗口并刷新父窗口的JavaScript代码,通过使用`window.opener.location.reload()`和`window.close()`,实现页面刷新和窗口关闭的功能。适合前端开发者了解和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. onclick="window.opener.location.reload();window.opener =null;window.close();"
 
关闭该窗口并 刷新父窗口
### JavaFX 关闭窗口刷新父窗口特定组件 在 JavaFX 中实现关闭窗口刷新父窗口中的特定组件,通常涉及事件处理机制以及父窗口之间的通信。当窗口执行某些操作(如保存数据),这些更改应当能够反映到父窗口的相关 UI 控件上。 为了达到这一目的,在创建窗口时可以传递对父窗口或者其内部方法的引用,以便于窗口能够在关闭前调用父窗口的方法来更新界面状态[^1]: ```java // ParentController.java public class ParentController { @FXML private Label statusLabel; public void openChildWindow() throws IOException { FXMLLoader loader = new FXMLLoader(getClass().getResource("child.fxml")); Stage stage = new Stage(); Scene scene = new Scene(loader.load()); ChildController childCtrl = loader.getController(); childCtrl.setParent(this); stage.setScene(scene); stage.showAndWait(); // Wait until the child window is closed refreshSpecificComponent(); } protected void refreshSpecificComponent(){ Platform.runLater(() -> { this.statusLabel.setText("Updated after closing child"); }); } } ``` 对于控制器而言,则需定义一个 `setParent` 方法接收来自父级的对象实例,在其自身的逻辑中适当位置触发父类提供的接口函数: ```java // ChildController.java public class ChildController { private ParentController parent; public void setParent(ParentController p){ this.parent=p; } @FXML private void handleSaveAndClose(ActionEvent event) throws Exception{ // Perform save operations here... ((Node)(event.getSource())).getScene().getWindow().hide(); if (parent != null){ parent.refreshSpecificComponent(); } } } ``` 通过上述方式可以在关闭窗体之后通知父窗体进行必要的UI重绘工作,从而保持应用程序的一致性和响应性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值