如何使用jquery从IFrame本身更改IFrame样式? [英] How to change IFrame styles from IFrame itself using jquery?

查看:713
本文介绍了如何使用jquery从IFrame本身更改IFrame样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe会使用以下脚本动态插入父页面(我无法控制此域)...

I have an iframe which will be inserted dynamically into the parent page (I don't have control over this domain) using following script...

var _hf_iFrame = document.createElement("iframe");
_hf_iFrame.setAttribute("id", "_hf_iFrame");
_hf_iFrame.setAttribute("name", "_hf_iFrame");
_hf_iFrame.setAttribute("style", "height: 354px; width: 445px; border: 0; margin-left: -400px; top: 23%; position: fixed;");
document.body.appendChild(_hf_iFrame);
_hf_iFrame.setAttribute("src", "http://anotherdomain.com/frame.html");

我想从iframe本身更改iframe的css属性。
是否可以实现这一点?我在我的iframe中使用JQuery。

I want to change the css properties of the iframe from iframe itself. Is it possible to achieve this? I am using JQuery inside my iframe.

提前感谢。

推荐答案

p>你不能这样做。

You can't do this.

您有两个文件。父和框架。 iframe元素存在于父代,所以要修改它需要修改父文档。

You have two documents. The parent and the framed. The iframe element exists within the parent, so to modify it you need to modify the parent document.

您的代码在框架文档中运行,这是在不同的域,因此同源政策会阻止您到达父级文档以进行修改。

Your code runs in the framed document, which is on a different domain, so the same origin policy prevents you from reaching the parent document to modify it.

这篇关于如何使用jquery从IFrame本身更改IFrame样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆