iframe在Chrome / Safari浏览器中使用scrollheight调整大小 [英] iframe resizing with scrollheight in chrome/safari

查看:135
本文介绍了iframe在Chrome / Safari浏览器中使用scrollheight调整大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据其内容调整大小(制作更大或更小)的iframe。点击每个页面后,会调用一个调整大小的方法。



在Chrome中,我可以使iframe变大但不能变小。 document.body.scrollHeight始终是最大的价值。因此,如果一个大页面设置了#iframe.height ='620px',并且有人点击了内容较少的页面的链接,那么scrollHeight将保持在620px而不是减少。



在Chrome / Safari中处理此问题的正确方法是什么?

解决方案

在你要求iframe中文档的高度之前,你应该设置iframe对象的高度为auto。像这样:

  objIframe = document.getElementById('theIframeId'); 
objIframe.style.height ='auto';

现在:

  document.body.scrollHeight 

返回文档的实际高度。 p>

I'm trying to resize (make bigger or smaller) an iframe based on it's contents. After a click on each page a method is called which does the resizing.

In Chrome I can make the iframe bigger, but not smaller. document.body.scrollHeight is always the biggest value.

So if one big page sets #iframe.height = '620px', and someone clicks on a link to page with less content scrollHeight will remain at 620px instead of decreasing.

What's the proper way of handling this in Chrome/Safari?

解决方案

Before you ask for the height of the document inside the iframe you should set the height of the iframe object to "auto". Something like this:

objIframe = document.getElementById('theIframeId');    
objIframe.style.height = 'auto';

And now:

document.body.scrollHeight

returns the actual height of the document.

这篇关于iframe在Chrome / Safari浏览器中使用scrollheight调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆