Container and Popup Cleanup

There are two containers in the popup.
There is a popup close icon.
Now the question is:
How to clear the popup data when clicking on the window close icon?
How to prevent a popup window from closing outside of a mouse click?
How to clear popup data outside of mouse click?