简体   繁体   中英

How to access parent dom element from child iframe?

parent domain is

example.com/abc/

and the iframe's domain is

abcd.example.com/hhh/.

is it possible to access the dom element of parent?

Is it possible? Yes. But only if you have permission to do so. Do you control both domains? If not then, no, this is not possible due to cross domain security restrictions.

Assuming you do have control over both sites you could use window.postMessage to facilitate this communication.

See this

Yes u can access it until both are on the same domain.

To access a parent element from iframe u can use javascript at child as follows:

parent.document.getElementById('elem');

To access any global element :

var a=parent.a

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