# How do I close A popup view with a button on it?

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [August 21, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946 "2024-08-21T15:08:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Farhan\_Basheer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/farhan_basheer/32/66759_2.png) [@Farhan\_Basheer](https://forum.inductiveautomation.com/u/Farhan_Basheer)\
**Post date:** [August 21, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946/1 "2024-08-21T15:08:21Z")

</div>

Hey Everyone,  
I am new to this community and I have a question.  
I have a popup view that I want to close with a button on it. How can I achieve this task?  
I have recorded a short video which describes the workflow and issue.  
[Link of the Explanatory Video](https://drive.google.com/file/d/11gpoUWRe7vT5ct7qzm42JPoNdUUbF7io/view?usp=sharing)

I have a View "BrassTag" where I have a "Save" button, When I click it, it opens a Popup, this popup then Have another button. I want to close this popup and the "BrassTag" view when this "Button" is clicked. I have tried everything but unable to achieve it. Can anybody help me in figuring out the issue?

---

<div class="post-metadata">

**Author:** ![flexware](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/flexware/32/66243_2.png) [@flexware](https://forum.inductiveautomation.com/u/flexware)\
**Post date:** [August 21, 2024, 3:20pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946/2 "2024-08-21T15:20:49Z")

</div>

On your inner view (i.e. the one with "Button"), when you specify the `ClosePopup` event, you need to pass in the same `popupId` so that it knows which popup to close.

So, at 0:16 seconds into the video, you can see `M62jlFBT` as the popup ID. You need to copy that identifier into the Identifier field that's displayed at 0:42 - the action on "Button".

 ![Change Identifier to M62jlFBT](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/436b862e950d0ea83007aa8614a9d0675a383264.jpeg)

I usually don't open/close popups this way - usually I call `system.perspective.openPopup` and `system.perspective.closePopup` and that is how I'm inferring that the Identifier is what is misconfigured (you need to also pass an `id` when using the scripting equivalent).

---

<div class="post-metadata">

**Author:** ![Farhan\_Basheer](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/farhan_basheer/32/66759_2.png) [@Farhan\_Basheer](https://forum.inductiveautomation.com/u/Farhan_Basheer)\
**Post date:** [August 21, 2024, 3:30pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946/3 "2024-08-21T15:30:27Z")

</div>

Thank you so much, it worked like a charm. And Thank you for guiding me towards the right way of opening and closing the popups. I will follow the convention.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 21, 2024, 3:37pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946/4 "2024-08-21T15:37:22Z")

</div>

I didn't watch the video but I notice that you have two actions in the onActionPerformed event. Be aware that these operate asynchronously.

Many have got caught out by a Popup Close action executing before the preceding Script action has executed. You can avoid this problem by putting the `system.perspective.closePopup` instruction into the script _after_ whatever else has to be done first (such as saving form data).

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 21, 2024, 4:44pm UTC](https://forum.inductiveautomation.com/t/how-do-i-close-a-popup-view-with-a-button-on-it/94946/5 "2024-08-21T16:44:13Z")

</div>

I'm not sure what you're calling the "right way", but opening popups with the built-in action is perfectly reasonable.

I'll suggest one thing: Pass the popup's id as a parameter to the view. This way, you can use that parameter to close the popup without having to hardcode the id into your view.

Also note that the popup id is actually used to build the element's DOM id, so if you control that id you can use it in the css stylesheet to greatly enhance the look and feel of your popups.

I even use it to "hack" themes on projects where I can't use actual theming.  
ie: I make the popup's id start with `{session.props.theme}`, then I can target them with selectors like `.ia_popup[id^=popup-light` or `.ia_popup[id^=popup-dark` and apply different styles based on what theme was selected.

I guess what I'm trying to say is, pay extra attention to how you setup your popups, it can open up a world of possibilities.
