热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iframe自适应子元素高度,第二个iframe的高度不对

1.tab切换不同的iframe显示,我在iframe的onload上写了一个setIframeHeight(iframe)函数,目的是iframe的高度自适应。2.我单独查看嵌入ifr

1.tab切换不同的iframe显示,我在iframe的onload上写了一个setIframeHeight(iframe)函数,目的是iframe的高度自适应。
2.我单独查看嵌入iframe的第一个网页personInfo.html和第二个的网页personModify.html内容,高度都是200多.
3.但是查看整个嵌入的页面index.html,第一个加载的iframe的高度是根据加载的网页内容的高度来的,确实是200多,但是第二个iframe的高度却多了好多,变成了650多,不知道是怎么回事,还望指教指教。
4.截图:
图片描述
图片描述

图片描述

代码:

index.html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33




   

       

       

       

   

   

       


           


               

           


           

       


       

       

   


index.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
body,a,span,li,ul,ol,p{

    padding: 0;

    margin: 0;

}

html,body{

    width: 100%;

}

body{

    font-family: sans-serif,"微软雅黑";

    font-size: 16px;

    background-color: #f4f4f4;

}

em{

    font-style: normal;

}

a{

    color: #fff;

    text-decoration: none;

}

li{

    list-style: none;

}

.left{

    float: left;

}

.right{

    float: right;

}

.clearfix::before,.clearfix::after{

    content: "";

    display: block;

    height: 0;

    visibility: hidden;

    clear: both;

}

/**布局

----------------------------------------*/

.container{

    width: 100%;

    height: auto;

}

.header{

    width: 100%;

    background-color: #52c3dd;    

    color: #fff;

}

.headerwarp{

    width: 80%;

    margin: 0 auto;

    height: 70px;

}

.section{

    width: 100%;

    margin: 20px auto;

}

/**导航

----------------------------------------*/

.headerwarp .logo{

    width: 70%;

    height: 100%;

    text-align: left;

}

/*.logo .logoInfo{

    height: 100%;

}*/

/*.logo  img{

    width: 70px;

    height: 70px;

}*/





.logo  span{

    line-height: 70px;

    vertical-align: middle;

    font-size: 30px;

}

.user{

    width: 30%;

    height: 100%;

    text-align: right;

}

.user a{

    font-size: 16px;

    line-height: 70px;

    color: #fff;

    text-decoration: none;

}





/**主体

----------------------------------*/

.sectionInfo{

    width: 80%;

    margin: 0 auto;

}

.sectionInfo .tab{

    width: 20%;

    /*height: 200px;*/

}

.sectionInfo .myCon{

    width: calc(100% - 20% - 10px);

}

.tab ul li{

    line-height: 50px;

    text-align: center;

    background-color: #52c3dd;

    border-bottom: 1px solid #FFFFFF;

}

.tab ul li:last-child{

    border: none;

}

.tab ul li:hover{

    background-color: #373E40;

}

.tab ul li:hover a{

    color: #fff;

}

.tab ul li.active,.tab ul li.active:hover{

    background-color: #373E40;

}

.tab ul li.active a,.tab ul li.active:hover a{

    color: #fff;

}

.tab ul li a{

    color: #fff;

}

.myCon{

    float: right;

   

}



iframe{

    min-height: 200px;

    border: none;

    display: none;

}

iframe.active{

    display: block;

}

index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
window.Onload= function(){

    //tab切换

    var tab = document.getElementById('tab');

    var tabLi = document.getElementsByTagName('li');

   

    var con = document.getElementById('myCon');

    var cOnIframe= con.getElementsByClassName('conHTML');

   

    if(tabLi.length != conIframe.length){

        return;

    }else{

        for(var i = 0;i
            tabLi[i].index = i;

            tabLi[i].Onclick= function(){

                for(var j = 0;j
                    tabLi[j].className = '';

                    conIframe[j].className = 'conHTML';

                   

                    this.className = 'active';

                    conIframe[this.index].className = 'conHTML active';

                }

               

            }

        }

    }

}



function setIframeHeight(iframe){

        if(iframe){

            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;

            if(iframeWin.document.body){

                iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;

            }

        }

    }

personInfo.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30




   

       

       

       

   

   

       


           

               

                   

                   

               

               

                   

                   

               

               

                   

                   

               

               

                   

                   

               

           


       


   


personModify.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34




   

       

       

       

   

   

       


           

               

                   

                   

               

               

                   

                   

               

               

                   

                   

               

               

                   

                   

               

               

                   

                   

               

           


       


   


personInfo.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
body,a,span,li,ul,ol,p{

    padding: 0;

    margin: 0;

}

html,body{

    width: 100%;

    height: auto;

}

body{

    font-family: sans-serif,"微软雅黑";

    font-size: 16px;

    background-color: #f4f4f4;

}

em{

    font-style: normal;

}

a{

    color: #fff;

    text-decoration: none;

}

li{

    list-style: none;

}

.container{

    width: 100%;

    height: auto;

}

.userTable{

    width: 50%;

    margin: 0 auto;

}

.userTable tr{

    line-height: 50px;

}

.userTable tr td:first-child{

    color: #52c3dd;

}

.userTable{

    text-align: center;

    margin-top: 20px;

}

.userTable td{

    text-align: center;

    vertical-align: middle;

    border-bottom: 1px solid #52c3dd;

}

.userTable tr:last-child td{

    border: none;

}

.userTable td input{

    width: 70%;

    line-height: 30px;

    vertical-align: middle;

    text-align: center;

    background-color: #fff;

    border-radius: 8px;

    outline: none;

    border: none;

}



推荐阅读
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文总结了在编写JS代码时,不同浏览器间的兼容性差异,并提供了相应的解决方法。其中包括阻止默认事件的代码示例和猎取兄弟节点的函数。这些方法可以帮助开发者在不同浏览器上实现一致的功能。 ... [详细]
  • DOM事件大全
    1.事件:js与html的交互就是通过事件的,观察者模式2.事件流:从页面中接收事件的顺序IE::事件冒泡流,事件冒泡,事件从最具体的元素接收,然后逐级向上传播,主流浏览器都支持N ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • 导出功能protectedvoidbtnExport(objectsender,EventArgse){用来打开下载窗口stringfileName中 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 本文介绍了响应式页面的概念和实现方式,包括针对不同终端制作特定页面和制作一个页面适应不同终端的显示。分析了两种实现方式的优缺点,提出了选择方案的建议。同时,对于响应式页面的需求和背景进行了讨论,解释了为什么需要响应式页面。 ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • 本文整理了Java中java.lang.NoSuchMethodError.getMessage()方法的一些代码示例,展示了NoSuchMethodErr ... [详细]
  • Tkinter Frame容器grid布局并使用Scrollbar滚动原理
    本文介绍了如何使用Tkinter实现Frame容器的grid布局,并通过Scrollbar实现滚动效果。通过将Canvas作为父容器,使用滚动Canvas来滚动Frame,实现了在Frame中添加多个按钮,并通过Scrollbar进行滚动。同时,还介绍了更新Frame大小和绑定滚动按钮的方法,以及配置Scrollbar的相关参数。 ... [详细]
  • asp中如何嵌入python的简单介绍
    本文目录一览:1、如何在IIS中执行Python脚本 ... [详细]
  • 工作经验谈之-让百度地图API调用数据库内容 及详解
    这段时间,所在项目中要用到的一个模块,就是让数据库中的内容在百度地图上展现出来,如经纬度。主要实现以下几点功能:1.读取数据库中的经纬度值在百度上标注出来。2.点击标注弹出对应信息。3 ... [详细]
  • html结构 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
author-avatar
幸福的小馋豆
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有