如何设置webView的iframe高度以适合其动态加载的内容的高度

时间:2018-11-29 12:56:08

标签: html iframe android-webview

对于具有listView的Android应用,每个项目都有一个加载html的WebView。

wv.loadDataWithBaseURL(                 baseUrl,                 htmlStr,                 “ text / html”,                 “ UTF-8”,为空             )

htmlStr具有模板,并为位于不同位置的项目填充了不同的参数:

<Html>
<head><meta http-equiv="Content-Security-Policy" 
       content="upgrade-insecure-requests">
       <link rel="stylesheet" type="text/css" href="android_asset/css/data-details.css">
</head>
<body>

<p> content part1 </p>

<p>
<iframe width="100% !important" height="800px"
  src="//internalapi.com/external/widget/partner-widget.php?height=800px&amp;
  width=640px&amp;param1=p1&amp;param2=p2&amp" frameborder="0" scrolling="no" allowfullscreen="">
</iframe>
</p>

<p> content part2 </p>

</body>
</html>

此html模板具有的唯一样式(将html内容加载到iframe的第三部分之外)是:

body {
        display: block;
        margin: 8px;
}

iframe {
        width: 100% !important;
}

iframe从第3方加载html内容,该html内容的表具有不同的行数。 因此显示内容分为三个部分:

[内容部分1]

[iframe的文档部分    其中会加载带有表格的html]

[内容第2部分]

  1. 使用height =“ 800px” <iframe width="100% !important" height="800px">

它始终以800像素显示,并且有时如果表中没有行,则在表标题下显示较大的空白空间。

,并且如果表格有更多行,则底部的某些行将不会显示(并且它不会滚动,设置为scrolling =“ yes”或“ no”都没有关系。当尝试滚动表格的内容时,整个列表滚动)

  1. 使用height =“ auto” <iframe width="100% !important" height="auto">

iframe内容部分仅以较小的高度显示(大多数时间看到的是150px)

  1. 使用height =“ 100%!important” <iframe width="100% !important" height="100% !important">

iframe内容部分仅显示高度为8px的条带。

问题:

在Web视图中,当它托管的html内部包含iframe且iframe动态加载其内容时,
并且内容可能具有非静态高度,如何使iframe显示与html内容高度相同的所有内容?

0 个答案:

没有答案
相关问题