views:

553

answers:

2

Hi,

I have an iFrame with an external website. I know about the same domain rule, so I am trying to invoke some javascript via the src to the parent. Currently I have:

<iframe id="my_frame" src="http://other.com"&gt;&lt;/iframe&gt;

and I change the src using javascript as follows:

<iframe id="my_frame" src="javascript:document.write("blah");"></iframe>

but using the parent does not work:

<iframe id="my_frame" src="javascript:parent.document.write("blah");"></iframe>

Does the same domain rule also apply for the parent or am I doing something wrong?

A: 

This is either a workaround gone awry, or it's genius and I don't recognize it :) What exactly are you trying to achieve? Do you want to write into the sub-frame, or from the sub-frame into the parent document?

Pekka
I actually thought it is something new, and tried the codes. Well, guess it is not genius. :P
o.k.w
A: 

I am guessing your intention is to write something to the document containing the iframe.

now, first off, your first snippet can't work because the double-quoted string inside the javascript is itself inside an attribute value, which is also enclosed in double quotes. It should read:

<iframe id="my_frame" src="javascript:document.write('blah');"></iframe>

This is probably also wrong in your last snippet, so fix accordingly.

Still, I don't really see what you are trying to achieve. Care to explain why you are trying to use this?

Roland Bouman