Presumably by "an automatic pop up window" you mean a pop-up which is triggered when the user leaves your page.
You can use onbeforeunload (not supported by all browsers) to display a pre-exit message or confirm box, but you cannot redirect the current window or open a modal dialog from the current window in the onbeforeunload event - if that was possible the internet would be unuseable.
Be aware that many people very much dislike this sort of thing, and do not wish to confirm that they want to move on to another page.
BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's assistance for granted. If you find this response helpful then please use the "Thank You For This Post" button.