- I have a
customer.jsp
page with aniframe
. iframe
has a button. on click of the button, i need to access a dialog box which is insidecustomer.jsp
page.- I tried
window.parent.document.getElementById('formDialog');
but am gettingnull
value.
- I have a
customer.jsp
page with aniframe
. iframe
has a button. on click of the button, i need to access a dialog box which is insidecustomer.jsp
page.- I tried
window.parent.document.getElementById('formDialog');
but am gettingnull
value.
- you have 500 correct answers, pick one – I wrestled a bear once. Commented May 4, 2014 at 16:47
4 Answers
Reset to default 9window.parent.document.getElementById('target');
both resources should be on same origin
Communication between an iframe and parent document is not possible for cross-origin resources. It will only work if the iframe and the containing page are from the same host, port and protocol - e.g. http://example.com:80/1.html and http://example.com:80/2.html
Assuming both resources are from the same origin
In the iframe, window.parent refers to the global object of the parent document, not the document object itself. I believe you would need to use parent.document.getElementById('formDialog')
You can access parent window elements through parent.document.getElementById('formDialog');
If you get null are you able to get that element within the context of that Iframes parent? Are you referencing the right ID and the right parent?
Try this. Hope this helps. Let's say I have CallParentFunction from button click of a button in an iframe.
function CallParentFunction(){
if (top && top.opener && top.opener.top) {
top.opener.document.getElementById('formDialog');
}
else {
top.document.getElementById('formDialog');
}
}