customer.jsp
page with an iframe
.iframe
has a button. on click of the button, i need to access a dialog box which is inside customer.jsp
page.window.parent.document.getElementById('formDialog');
but am getting null
value.JavascriptWeb DevelopmentFront End Technology. To call a parent window function, use “window.top”. You can try to run the following code to call a parent window function from an iframe.
As the iframe got an ID named 'source'. So, with javascript, it's simple to get the element. var destination = document.getElementById ('destination'); But as we are targetting the content inside the iframe, we need to address the contentwindow inside the iframe. So the code will be like below -
Cross-origin communication in between iframe and it’s parent website is not any hack or something, but with simple functions you can make it happen Yes, it's not any hack or something, but with simple functions you can communicate in between iframe and it's parent website.
To send a message using window.postMessage method: you need to add event listeners in the parent to receive messages from iframe Note: this method can be used in same-domain iframe also.
window.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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With