How would I make a window open up only if the back button or x button is used?

In short I don't want it to open if a link is clicked.

Your help will be much appreciated

"I find that the harder I work, the more luck I seem to have."
- Thomas Jefferson