下面的 html 被加载到 WebView 上。
在特定的时刻,javascript 函数 toggleLayer() 被调用并更改内部 div 的属性“显示”以在“扩展”和“正常”层之间切换。
这在 Android KitKat 之前工作正常,但在 Lollipop 中,WebView 在图层更改后不会更新其内容。
我相信它发生在新版本的 WebView 中的一些改进,但我不知道它到底是什么。
这种行为在 Lolipop WebViews 中知道吗?当内容发生变化时,我该如何解决它并让 WebView 自行更新?
<div id="adContainer" style="width:320px;margin:0px;padding:0px;background-color:#ffffff;">
<div id="normal" style="display:none;width:320px;height:50px;margin:auto;position:relative;top:0px;left:0px;">
<img width="320" height="50" src="http://admarvel.s3.amazonaws.com/demo/mraid/320x50_click_to_expand.png" onclick="javascript:expand();"/>
</div>
<div id="expanded" style="display:none;width:320px;height:250px;margin:auto;position:relative;top:0px;left:0px;">
<img width="320" height="250" style="position:absolute;top:0px;left:0px;" src="http://admarvel.s3.amazonaws.com/demo/mraid/320x250.png" />
<img width="37" height="37" style="position:absolute;top:125px;left:56px;" src="http://admarvel.s3.amazonaws.com/demo/mraid/Html_37x37.png" onclick="javascript:openSite('http://www.opera.com');" />
<img width="37" height="37" style="position:absolute;top:125px;left:113px;" src="http://admarvel.s3.amazonaws.com/demo/mraid/Location_37x37.png" onclick="javascript:openSite('https://maps.google.com/maps?q=1875+S+Grant+St,+San+Mateo,+CA&hl=en&sll=46.238212,6.864936&sspn=0.135592,0.222816&oq=1875+S&hnear=1875+S+Grant+St,+San+Mateo,+California+94402&t=m&z=17&iwloc=A')" />
<img width="37" height="37" style="position:absolute;top:125px;left:170px;" src="http://admarvel.s3.amazonaws.com/demo/mraid/Download_37x37.png" onclick="javascript:openSite('https://itunes.apple.com/us/app/opera-mini-web-browser/id363729560?mt=8&ign-mpt=uo%3D4');" />
<img width="37" height="37" style="position:absolute;top:125px;left:227px;" src="http://admarvel.s3.amazonaws.com/demo/mraid/Video_37x37.png" onclick="javascript:openSite('http://admarvel.s3.amazonaws.com/demo/mraid/OMW_SOUND_VIDEO_RENEW.iPhoneSmall.mp4');" />
</div>
<script language="javascript" type="text/javascript">
function toggleLayer( fromLayer, toLayer )
{
var fromElem, toElem, fromElemStyle, toElemStyle;
fromElem = document.getElementById( fromLayer );
fromElem.style.display = 'none';
toElem = document.getElementById( toLayer );
toElem.style.display = '';
}
</script>