# How to close popup when screen changes?

**URL:** <https://forum.inductiveautomation.com/t/how-to-close-popup-when-screen-changes/68690>\
**Category:** Ignition\
**Tags:** ignition81, ignition80, perspective\
**Created:** [January 17, 2023, 8:39pm UTC](https://forum.inductiveautomation.com/t/how-to-close-popup-when-screen-changes/68690 "2023-01-17T20:39:53Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 18, 2023, 6:02pm UTC](https://forum.inductiveautomation.com/t/how-to-close-popup-when-screen-changes/68690/8 "2023-01-18T18:02:45Z")

</div>

In addition to the quick-and-dirty avenue I already supplied, there's two other ways to do this.

**More correct:**  
In the `onShutdown` Event script for the View in question, close out all "known" Popups for the View.

```auto
known_popup_ids = ["a", "b", "c"]
for popup_id in known_popup_ids:
    system.perspective.closePopup(id=popup_id)

```

This requires you to always update the list of potential Popups, so this is inherently brittle as you develop and add more content. Additionally, there is always the possibility of other Views (Popups, Docked Views) opening their own Popups, and this View would know nothing about them.

**Most correct:**  
In the `onShutdown` Event script for the View in question, broadcast that all Popups should be closed for the page.

```auto
system.perspective.sendMessage(messageType="CLOSEPOPUPS", scope="page")

```

This route requires that EVERY POPUP have at least one component which has a configured Message Handler listening at the page scope for a "CLOSEPOPUPS" message. It also requires that the Popup either knows its own ID (passed in as a parameter perhaps, or hard-coded as a custom prop). You are not able to rely on supplying an empty-string id because there could be other Popups which would be closed.

```auto
system.perspective.closePopup(id="MyKnownId")

```

This route is the "most correct" because there is no list of Popups to manage as development continues, and it allows the individual Popups to manage their own lifecycle. Also, this route will also act on Popups opened from other Views as long as they too have a configured Message Handler and ID.

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-to-close-popup-when-screen-changes/68690)._
