user1649874
user1649874

Reputation: 21

Listening from a iframe event

On my page (index.htm) i have a iframe inside a modal that loads a content i.e (pagex.htm) from a different domain (not owned by me).

This iframe with (pagex.htm) has a element with id (#close) that also have a onclick() event as below:

<a id="close-lite" class="ch-close" onclick="closeRender();" href="#">×</a>

In my index.htm i have my jquery/javascript and what im trying to do is to access the iframe and get the click event to close the modal that is inside my page (so im not trying to modify the iframe content). I have tried to use .content() but without sucess yet.

Perhaps is a cross domain policy ussue? how can i get around this?

How can i do this with javascript/jquery ?

Upvotes: 1

Views: 799

Answers (2)

Max Tatarchenko
Max Tatarchenko

Reputation: 41

Can be used postMessage().

http://robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/

But it works not in all browsers and needs init from both sides.

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114427

The same-origin-policy prevents you from listening to what is going on in the Iframe.

Upvotes: 2

Related Questions