views:

53

answers:

1

I have a page with an iframe that contains a html page. I want to access a javascript variable in the parent page from within the iframe. The name of the variable in the main page is "observer".

I try and do the following in the iframe page:

parent.observer = 'aadasds';

but I am getting the following error:

Permission denied for to get property Window.observer from .

A: 

Exchanging values between iframes (and parent) is only allowed if both sites come from the same domain. If they do, your example should just work. If they don't, browsers inhibit the communication.

However there are a number of hacks to circumvent this: e.g the Yahoo.CrossFrame library described in Julien le Comte's blog using a third iframe to enable one way communication, or the "resize an iframe around the iframe"-idea described in Adam Fortuna's blog enabling two way communication.

tec
"Exchanging values between iframes (and parent) is only allowed if both sites come from the same domain. If they do, your example should just work. If they don't, browsers inhibit the communication." - can a javascript function on the page be called from the page inside the iframe?
Niall Collins
@Niall Collins: Yes, without problems - as long as both pages come from the same domain. The error message you describe only appears if they originate from different domains, as far as I know.
tec