javascript - IE9 忽略滚动和溢出属性

标签 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 + '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/

相关文章:

javascript - 函数获取指定字符串中每个字母出现的次数

javascript - 如何将 forEach 映射到 angularJS 中的 Accordion

php - 使用 PHP 在 HTML 中显示下拉列表

css - 设置宽度 div 内的全宽背景图像

javascript - 在网页顶部显示验证摘要时控件定位不正确

javascript - 如何通过 NODE.js javascript 代码中的大写转换来查询 SQL 数据库中的列。

javascript - 使用 document.write 对象渲染鼠标位置

html - SASS 引用特定的父选择器

javascript - jQuery UI slider 通过外部控件向前和向后移动

javascript - 当滚动到达该 div 时更改内部 div 的 CSS