iframe 标签自适应高度和宽度

iframe 结构如下

<iframe src="index.html" id="frame" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" onLoad="iFrameHeight()"></iframe>

js 实现

<script type="text/javascript" language="javascript">
function iFrameHeight() {
    var ifm = document.getElementById("frame");
    var subWeb = document.frames ? document.frames["frame"].document : ifm.contentDocument;
    if (ifm != null && subWeb != null) {
        ifm.height = subWeb.body.scrollHeight;
        ifm.width = subWeb.body.scrollWidth;
    }
}
</script>

jQuery 实现

$("#frame").load(function(){
    var mainheight = $(this).contents().find("body").height()+30;
    $(this).height(mainheight);
}); 
时间: 2024-08-14 09:07:08

iframe 标签自适应高度和宽度的相关文章

&lt;iframe&gt;标签自适应高度和宽度

<iframe src="index.html" id="iframepage" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" onLoad="iFrameHeight()"></iframe> <script type="text/javascr

关于使用iframe标签自适应高度的使用

在ifrome内设定最小高度,(此方法只适用于页面内切换高度不一.但是会保留最大高度,返回后保持最大高度不再回到最初页面的高度) 1 <iframe id="one4" width="100%" height="1600px" src="merchant information.html" style="border:1px solid #f4f4f4;" scrolling="no&quo

EXT组件自适应高度和宽度

Ext代码 Ext的组件构造函数的width.height不支持100%的设置方式,因此动态获取高度宽度来解决问题. <div id="component" style="width:100%;height:100%"> <div> 组件构造的时候这样写: width: Ext.get("component").getWidth(), height: Ext.get("component").getHe

iframe框架自适应高度

问: 有一个页面niu.html代码如下 <iframe  src=http://www.iiwnet.com/about.html ></iframe> 页面的高度是通过about.html页面里BODY 传递的,但是我现在调用的是一个别的网站的东西.无法 在被调用的页面得到他的高度..请问我在niu.html页面里有办法实现 iframe 自动调整高度吗? 答: 当然可以~ 重要提示:src=中你必须填写的网页地址,一定要和本页面在同一个站点上,否则,会抱错,说"拒绝

UILabel 自适应高度,宽度

mLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 10, 1)]; mLabel1.text = @"my label 1, ok , ok , ok "; mLabel1.numberOfLines = 0; [mLabel1 sizeToFit]; 说明: 1. 如果只调用 sizeToFit,则label的位置不变,宽度会根据内容自适应,文本会只占1行 2. 如果设定numberOfLines = 0的同时调用si

iframe框架自适应高度 uncanght SecurityError: Blocked a frame with origin &quot;null&quot; from accessing a frame ....

来源于crm项目的contact/edit.html 一.背景是这样的 最近在做crm系统的前端页面,有一个页面呢,点击“查看全部信息”时会弹出,这个弹窗里面又有分页导航,分页不是使用ajax 异步刷新请求写的,而是通过刷新页面.由于整站的分页都是使用这个方法,所以不可能让后端同事用ajax重写一个分页,所以呢,就想到使用iframe框架,把这个弹窗写在html文件,放在iframe中完成.一切都是perfect的想法. 二.问题来了!解决问题 此时不仅仅是没有高度自适应而且还报错,其实这报的错

iframe 自适应高度和宽度

<iframe src="pay/index.aspx" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="100%" height="100%" frameborder="0" id="iframepage" name="

iframe实现自适应高度

代码简单,兼容性还可以 <script>function SetWinHeight(obj) {  var win=obj;  if (document.getElementById)  {   if (win && !window.opera)   {    if (win.contentDocument && win.contentDocument.body.offsetHeight)    win.height = win.contentDocument.

根据Label和字体大小自适应高度和宽度

- (void)getHeightWithLabel:(UILabel *)label andFontSize:(CGFloat)size { label.numberOfLines = 0; NSMutableAttributedString *labelString = [[NSMutableAttributedString alloc] initWithString:label.text]; [labelString addAttribute:NSFontAttributeName val