我的页面已加载到 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-Standards。
如何去掉IE9下iframe的那个滚动条?
最佳答案
当您执行此操作时,看起来 iframe
已加载。您可以设置:
iframe.contentWindow.document.body.style.overflow = 'hidden';
如果页面上有文字iframe
标签,可以将scrolling
属性设置为"no"
,但是当设置这个属性值时在为页面创建 iframe
元素后使用 JS 不起作用。如果您正在动态创建 iframe
,则可以在将其附加到文档之前设置 setAttribute('scrolling', 'no')
。
关于javascript - IE9 忽略滚动和溢出属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17862093/