CSS修改iframe内的样式问题

如何在iframe外控制iframe中的css?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title></title>
</head>
<body>
<iframe id="FF" src="B.htm"></iframe>
<input type="submit" value=" OK " onclick="OK()"/>

<script language="JavaScript">
function OK()
{
// 操作iframe中内容的CSS
var iframe = document.getElementByIdx('FF');
var body = iframe.contentWindow.document.body;

body.style.marginTop
=50;
body.style.padding
=0;
body.style.fontSize
=30;
body.style.textAlign
='center';
body.style.backgroundColor
='red';
body.style.color
='blue';
}
</script>
</body>
</html>

这样是可行的,前提是这个iframe是跟你的页面在一个域内,如果跨域了 var iframe = document.getElementById('FF'); 就报错“无访问权限”。

现在的问题就是跨域 怎么修改iframe中的样式。。待解决。。

转载于:https://www.cnblogs.com/smailxiaobai/archive/2011/11/25/2262780.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值