简体   繁体   中英

How can I get the value of an attribute inside an iframe from parent in Javascript?

How can I pass attribute value from iframe to parent?

Ie iframe (frame1) has <a id="a1" href="http://www.infinitybusiness.net"> . How can I get value of href in my parent page?

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.

This is a great tutorial that talks exactly about that: http://www.roseindia.net/java/pass-value-example/pass-value-from-iframe-parent.shtml

you can use it only if the two pages are served from the same domain. There are many solution for cross-domain scripting as well..you can read more here: http://softwareas.com/cross-domain-communication-with-iframes

it is easy:

  • you should use %26 instead of & to send to iframe

for instance : Link : 2.asp?ppp=/Payam.asp?sid=1%26PID=1&sa=12313 in Code : when i requset.queryString("ppp") in the parent it shows: /Payam.asp?sid=1&PID=1

you can use this as source of your iframe , it has two parameter

<IFRAME name="My"  src='<%=ppp %>'></IFRAME>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM