开发者

iFrame and Javascript to parent document

I have an iFrame with an external website. I know about the same domain rule, so I am trying to i开发者_开发知识库nvoke some javascript via the src to the parent. Currently I have:

<iframe id="my_frame" src="http://other.com"></iframe>

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?


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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜