2

What methods are available to monitor the status of IFRAME page, I know there are security limits but I hope some small notification system is still possible.

My situation is that I have created a parent page that is located on customer's server, and this page has has iframe page located on my server (my domain). I need to somehow communicate a little between these two:

Can I make javascript to the parent page that can check if my iframe page has a specific string on it, or somehow make iframe page to notify the parent page?

Is there e.g. any possibility to make a timer that checks iframe content time to time?

I also accept answer how mydomain/client.page calls callback on customerdomain.intranet.com/parentpage.htm that has client on iframe

Tom
  • 6,725
  • 24
  • 95
  • 159

3 Answers3

1

You need to use cross site JavaScript techniques to be able to do this. Here is an example.

Put another file into your server, call it helper.html, include it to your file served by customers server using an iframe. Set the src of the helper.html iframe with adding get parameters, ie. http:/myserver.com/helper.html?param1=a&param2=b, in the helper file use javascript to call method on parent's parent ( parent.parent.messageFromIframe(params) ). Which is the page on your server itself. Since helper and the container page are on the same domain it should work. The technique is popular, for instance Facebook was using it for their Javascript api.

M. Utku ALTINKAYA
  • 2,254
  • 23
  • 29
  • sorry dont fully understand this one.. sounds good ! can you give more details. I want to communicate between 2 domains. – Tom Aug 24 '09 at 12:06
  • basically you communicate with the helper file bey setting the src iframe contains it and passing parameters. the js code inside the helper can access the parent's parent's functions, which means you can call any js code inside your own container page. – M. Utku ALTINKAYA Aug 24 '09 at 12:27
  • so you mean there is recursive iframe, another iframe inside my iframe? – Tom Aug 24 '09 at 12:49
  • yes an iframe which loads a page from the container's server inside iframed page. – M. Utku ALTINKAYA Aug 24 '09 at 15:23
  • thanks, but customer server is located inside intranet, so there is no access from public server to that direction. – Tom Aug 25 '09 at 06:47
1

I got information that this is possible by setting parent.location (from iframe) to have hash data like this "mydomain.com/mypage#mymessage"

Tom
  • 6,725
  • 24
  • 95
  • 159
0

By default, security restrictions in the browser will prevent access from/to the document in the iframe if it is in a different domain to the parent page. This is, of course, just as it should be.

I believe this would prevent even checking the current location of the iframe, but that's easily testable. If it's accessible, then you could poll the iframe for its location, and whenever the page in the iframe updates, have it append a random querystring parameter. Comparison of that parameter to the value from the previous poll would tell you if it's changed.

However, as I say, I suspect it's not possible.

Edit: This question suggests it is only possible for the initial src attribute: How do I get the current location of an iframe?

Community
  • 1
  • 1
Matt Sach
  • 1,162
  • 16
  • 37