How can I pass attribute value from iframe to parent?
I.e. iframe (frame1) has <a id="a1" href="http://www.infinitybusiness.net">
. How can I get value of href
in my parent page?
When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.
You can use a script to get the desired parameter value from parameters passed to page. Show activity on this post. If you have slightly more control on your iframe sandbox, you can try postMessage API to communicate with message on events you desire to trigger.
var fra = document.getElementById('frameId');
// following will work on same domain (or subdomain with document.domain set) only
var fraContent = fra.contentDocument || fra.contentWindow.document;
myLinkHref = fraContent.getElementById('myLinkId').href;
If this is cross-domain, then you will need to have access to add script to the child frame. If not, it can't be done without a server-side proxy.
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