In my application, it is using $modal.open() function to open a modal popup which is using another page as a template. While clicking the button, it is showing the
$modal.open()
Catch all clicks on the html document, and close the modal.
Catch clicks inside the modal and stop the propagation.
i.e.
$("html").on("click",closemodal()); $(".modal").on("click",function(event){ event.stopPropagation(); }