How to hide the content of Thank you page by using additional script

Hello All,
I need to hide the content of “Thank you” page and instead of that need to show custom pop-up.
But sometime there is an error in “Thank you” page which display the whole content of “Thank you” page and stop the additional script to load. I want the additional script to work always.
Please let me know how to handle this.

Thanks