Exit Button Works on Desktop but Leaves a White Screen in the Moodle App (window.close issue)

I added an Exit button to my project. When the user clicks the button, I want to close the window using the following code:

prez.destroy();
window.close();

However, when I click this button inside the Moodle app, the screen stays white instead of closing properly. On a desktop PC, it closes the browser tab as expected.

Is there a solution or recommended approach to handle exiting/closing the content properly in the Moodle app?