I have a project to not allow a form to be closed unless the user saves their changes first. The way the page is set up having the parent page, cshtml, to have a modal and inside that modal is an Iframe that has the form, html. I tried just editing the form to have a beforeunload eventlistner however the that does not work since the Iframe can only be hidden not closed. I am currently trying to connect the parent and child up to talk to each other by having:
parent.cshtml
<div class="modal-content">
<div class="modal-body" style="width:100%; height:75%;">
<div id="complianceIframeBody" style=" width: 100%; height: 100%;">
<iframe id="IframeHtml" class="iframe;" frameborder="0" allowfullscreen src=""></iframe>
</div>
</div>
<div class="modal-footer">
<button type="button" id="closeBtn" class="btnOk btn btn-default" data-dismiss="modal">Close</button>
</div>
<script>
function preventNaigation() {
window.onbeforeunload = function (e) {
return "Are you sure you want to navigate away from this page ? Any unsaved changes will be lost.";
}
}
</script>
child.html
<script>
$("#form0 :input").change(function () {
preventNavigation();
});
</script>
My question is how cna I have these two communicate in order for the Iframe to prompt the User they are leaving unsaved changes when they click a close button on the modal.


