我正在填充一个 iframe,其中包含一些注入其中的内容,但我无法正确调整它的大小。我尝试了多种方法,但这是最新的代码。
在使用基于 html 的邮件消息填充 iframe 后,它似乎没有注册滚动高度。
<iframe scrolling="no" width="100%" onload="javascript:(LoadIFrame(this));" >
HTML content goes here. Make sure it's long enough to need to scroll before testing.
</iframe>
<script type="text/javascript">
function LoadIFrame(iframe) {
$("iframe").each(function() {
$(this).load(function() {
var doc = this.document;
if (this.contentDocument) {
doc = this.contentDocument;
} else if (this.contentWindow) {
doc = this.contentWindow.document;
} else if (this.document) {
doc = this.document;
}
this.height = (doc.body.scrollHeight + 50) + 'px';
this.onload = '';
});
txt = $(this).text();
var doc = this.document;
if (this.contentDocument) {
doc = this.contentDocument;
} else if (this.contentWindow) {
doc = this.contentWindow.document;
} else if (this.document) {
doc = this.document;
}
doc.open();
doc.writeln(txt);
doc.close();
});
}
</script>