Javascript IE9忽略滚动和溢出属性

Javascript IE9忽略滚动和溢出属性,javascript,html,css,iframe,internet-explorer-9,Javascript,Html,Css,Iframe,Internet Explorer 9,我的页面被加载到iframe中,我需要使用javascript调整iframe的大小。我尝试以下方法: iframe.style.overflow = 'hidden' iframe.scrolling = 'no' var content = iframe.contentWindow.document.getElementById('content') var height = content.offsetHeight + 10 iframe.style.height = height + '

我的页面被加载到iframe中,我需要使用javascript调整iframe的大小。我尝试以下方法:

iframe.style.overflow = 'hidden'
iframe.scrolling = 'no'
var content = iframe.contentWindow.document.getElementById('content')
var height = content.offsetHeight + 10
iframe.style.height = height + 'px'
console.log(content.offsetWidth)
var width = content.offsetWidth + 10
iframe.style.width = width + 'px'
在FireFox上,它可以正常工作,但IE9忽略了滚动和溢出属性。浏览器模式设置为IE9标准


如何消除IE9下iframe中的滚动?

执行此操作时,iframe看起来像是加载了
iframe。您可以设置:

iframe.contentWindow.document.body.style.overflow = 'hidden';

如果页面上有一个literal
iframe
标记,您可以将
scrolling
属性设置为
“no”
,但在为页面创建
iframe
元素后使用JS设置此属性值时,该属性不起作用。如果动态创建
iframe
,可以在将其添加到文档之前设置
setAttribute('scrolling','no')

这正是我要做的。问题是,IE9忽略了这一点。与我在开发工具中设置的相同。不,不是,这设置了
iframe
中的样式,您正在尝试操作
iframe
元素本身。工作很好,只要我可以操作iframe的内容,在我的情况下我可以,但在一般情况下@ukaszLech您阅读了代码下面的文本吗?无论您是否将跨域内容加载到
iframe
,这两种技巧都适用于IE。您的问题似乎是如何在IE中禁用滚动,跨域内容访问在任何浏览器中都不起作用。啊,好的,我应该在设置src之前设置scrolling=“否”?这就是为什么我的JSFIDLE正在运行而我的生产代码没有运行的原因?我不能在IE10(通过开发工具激活与IE9的兼容模式)上用这个JSFIDLE复制它: