Closed micjohnson382 closed 8 years ago
I found the soultion thru this link.
https://github.com/niutech/showModalDialog/issues/5
But not sure what to do If my calling and the popup pages are located in different folders. I am getting "Uncaught TypeError: Cannot read property 'close' of undefined" error.
The directory should not matter, as long as the modal and the parent document are in the same origin. Then you should be able to acces the parent document from inside the modal using:
var parentDoc = parent.document;
var dialogElms = parentDoc.getElementsByTagName('dialog');
var firstDialog = dialogElms[0];
firstDialog.close();
If you get a TypeError, it means that the dialogElms
is empty.
Thank you very much for your reply. Yes I am getting a TypeError. I did check the length of dialogElms and it returned 0. I am using the exact code given here and Not sure why I am getting zero length.
Open Dev Tools and inspect the code provided. Check if parentDoc
points to the parent document, and if it contains a <dialog>
element. Also check if replacing parent
with top
will work.
Thank you very much. The code is working well after I added "parent." to reach my popup root level. var parentDoc = parent.parent.document; Appreciate your help.
to close from modal form: parent.document.getElementById('dialog-close').click();
I am able to close the popup using the X on the top right corner. I am trying to close the popup a thru a "Close" button from the iframe dialog-body content. I tried using removeChild function but failed.
I have tried with "self.parent.document.getElementsByTagName('dialog')[0].close()" but got this error "Uncaught TypeError: Cannot read property 'close' of undefined"
How do I do that? Appreciate your help.