The use of JavaScript
window.confirm
with
if
(if not with
if
then why?) is quite clearly explained, for example, here:
Window.confirm() - Web APIs | MDN[
^].
But could it be considered as a good solution? I would not say so, not for production-quality applications. Such methods give ugly look depending on the platform and browser, which may not be in line with your application styles, and badly limited in flexibility.
It would be much better to develop modal-like behavior inside a Web page, and do it fully locally, with JavaScript. The first solution would be this:
https://jqueryui.com/dialog[
^].
Also, there are many 3rd-party jQuery plug-ins, collectively known as "modal popup", with different effects, such as transitions, and, notably, dimming of the rest of the page. Please see:
http://bfy.tw/AJH[
^].
If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery,
http://jquery.com,
http://learn.jquery.com,
http://learn.jquery.com/using-jquery-core,
http://learn.jquery.com/about-jquery/how-jquery-works (start from here).
But you don't have to do it like that. In my article
Modal Popup From Scratch I explain how to it and explain the behavior and the rationale behind this design element.
—SA