# Close popup window using close button template

**URL:** <https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [February 14, 2025, 10:35pm UTC](https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390 "2025-02-14T22:35:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.black](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@michael.black](https://forum.inductiveautomation.com/u/michael.black)\
**Post date:** [February 14, 2025, 10:35pm UTC](https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390/1 "2025-02-14T22:35:56Z")

</div>

I have several templates I'd like to use a close button template on.  
I have the close button template with a template parameter of currentWindow. Here is the script I have applied to the button.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/583e379808826829a324b96d276f71351b78fd9a.png)

I dragged the template over on another template. I am having difficulties on what to bind the currentWindow template property to?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/d/ddbcaaac5fae49f9887ff97e72270005851c36b4.png)

Is there a tag I should be creating which updates all the time when a new popup window is opened?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 14, 2025, 10:53pm UTC](https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390/2 "2025-02-14T22:53:43Z")

</div>

```python
from javax.swing import SwingUtilities # https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/SwingUtilities.html#getAncestorOfClass(java.lang.Class,java.awt.Component)
from com.inductiveautomation.factorypmi.application import FPMIWindow # https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.45/com/inductiveautomation/factorypmi/application/FPMIWindow.html

window = SwingUtilities.getAncestorOfClass(FPMIWindow, event.source)
system.nav.closeWindow(window)

```

~~Should work on any button anywhere to close whatever window it's contained on.~~

Use the system function @zacht highlighted.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 14, 2025, 11:16pm UTC](https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390/3 "2025-02-14T23:16:30Z")

</div>

Is  
`window = SwingUtilities.getAncestorOfClass(FPMIWindow, event.source)`  
different from  
`window = system.gui.getParentWindow(event)`

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 14, 2025, 11:18pm UTC](https://forum.inductiveautomation.com/t/close-popup-window-using-close-button-template/102390/4 "2025-02-14T23:18:46Z")

</div>

Essentially, no:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/161e805b87aaf1f5c203c16d440cdcb4413b76e7.png)

But the system function is definitely preferred - first, you don't have to do any awkward importing, and second it takes care of some extra threading niceties and error messaging for you.

Totally forgot that it existed 😄
