Javascript confirmation popup in APEX

In my current project I’ve been trying to get a nice popup message to show when a user presses a button.
This can be done in several ways, of which most are cumbersome or hard to understand.

The easiest and (in my opinion) prettiest way is using a javascript popup. When Ok is pressed, the button performs it’s normal function. When Cancel is pressed, the focus returns to the page without submitting.
The only thing needed is a line of code on the URL target of the submit button.

If you want the button to submit when Ok in the popup is pressed, your code will look like this:

javascript:{if (confirm('Confirmation Message')) doSubmit('<button name>');}

If you want the button to redirect to a different page using a URL when Ok is pressed, you can use this code instead:

javascript:{if (confirm('Confirmation Message')) redirect('f?p=&APP_ID.:&APP_PAGE_ID.:&APP_SESSION.');}