tags:

views:

271

answers:

4

Hey! I am trying to get an iframe B communicate with site A. I've searched and searched and every thing I read says it's impossible if they are of different domain (the iframe src is coming from a sub domain).

I want to communicate because my company has ads on its page and it needs to refresh them every X minutes. This is ok if it's a normal add, but some adds extend. Like I have adds that start with 300x250 and then get to 800x300. I wanted to communicate to the iframe to know when the add was going to expand but it just doesn't seem to be a way. Is there any way to let the add go beyond the initial size of the iframe?

If the add is 300x250 the iframe will also have 300x250, but when the add expands it get's cut off, so I really need to either get the iframe to expand also or have the add go beyond the size of the iframe.

Anyone know how to do this or have some tutorial that shows how to have some basic communication to an iframe.

Note: There are some websites that also serve adds that have a totally different domain, so it would be great if someone knew how to make it go beyond the iframe.

Thanks

+1  A: 

You can't cross iframe boundaries for security reason, it would be straightforward to steal your login credentials to any site if that would be possible.

However you can make server side proxy, which would redirect every query from iframe to ads servers. That way your iframe could actually have source in the same domain (or subdomain)

vava
this is a page that has an iframe
AntonioCS
+2  A: 

If you want the two iframes to communicate and you say one is on a different subdomain but the same top-level domain, you can do inter-frame scripting. See http://ajaxian.com/archives/how-to-make-xmlhttprequest-calls-to-another-server-in-your-domain.

The trick is to get page A and B to both set

document.domain = 'SameTopLevelDomain.com';

and the browser will then let the pages communicate (eg grab data from the other, call functions, etc).

However if the two pages are on different domains altogether, you'd have to take the server-side proxy approach as answered earlier.

Crescent Fresh
A: 

Maybe my answer Cross-site AJAX requests will help you.

TcKs
A: 

There is a way to do cross-domain communication using iframes, described in an answer to Resizing an Iframe based on content.

Many ad-serving companies serve their banners on your site via iframes, and use the technique outlined in the answer above to ensure that the iframe can expand to the full required size of the creative.

ConroyP