5

i have an iframe in my page , and this iframe is not located on my server (src is not from my site).

how can i trigger a function as soon as the iframe getting redicrecting to a new target(src is changing)?

what i mean is when a user click on a link in the iframe and the iframe is redirecting him to the new target.. i need to trigger a function before it redirecting him , OR as soon as possible before the page is been showing up..

onclick and onload events get trigged when the iframe is getting fully loaded and that's not effective for me.

any advices could help!

ixcese
  • 53
  • 3
  • 1
    Read up on same origin policy. – Eugen Rieck Feb 14 '12 at 13:24
  • @EugenRieck but i think it's kind of possible because it still gives me option to know when it fully loaded , so why not in the beggining? – ixcese Feb 14 '12 at 13:27
  • 1
    `Onload` is an event of the iframe (which belongs to your page), but what happens INSIDE the iframe belongs to it. – Eugen Rieck Feb 14 '12 at 13:30
  • @EugenRieck so , there is not such an event which that belongs to my page that can detect when iframe is beeing redirected? – ixcese Feb 14 '12 at 17:18
  • How could there be? Being redirected is an event of the CONTENT of the iframe, not of the iframe itself. – Eugen Rieck Feb 14 '12 at 17:19
  • @EugenRieck i'm sorry i cant get it. i can know when the content is fully loaded but not when it start loading? – homerun Feb 14 '12 at 17:38
  • Yep. `Onload` is an event on the iframe, so your page as the owner of the iframe can listen to it. Everything INSIDE the iframe is out of your scope. – Eugen Rieck Feb 14 '12 at 17:47

1 Answers1

2

This can not be done due to the same origin policy.

On the other hand if you control the other site you can send cross domain messages, see: http://html5demos.com/postmessage2

Daniel Kurka
  • 7,973
  • 2
  • 24
  • 43