Sougata Bose
Sougata Bose

Reputation: 31739

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?

Upvotes: 1

Views: 9607

Answers (2)

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11707

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

Upvotes: 1

Nick
Nick

Reputation: 19664

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

Upvotes: 4

Related Questions