Hi,
The risk with having a JS snippet for the same would also trigger when you leave a webpage i.e open a link or go to a new-tab or press browser-bank-button.
If that is something you are ok with, then I would recommend you to have that snippet in LayoutWB itself & then you can either invoke your custom popup from there itself. Having the snippet on LayoutWB will be applied to every Screen of your app.
Hope it helps,
Assif