【发布时间】:2015-12-24 14:32:36
【问题描述】:
我有 WebView 内容,它会根据内容的数量改变它的高度。 所以我找到了一种方法,如何通过document.title属性onNavigationStateChange来获取内容的高度。 看起来像这样:
let html = '<!DOCTYPE html><html><body><script>document.title = document.height;</script></body></html>';
在 onNavigationStateChange 上
onNavigationStateChange(navState) {
this.setState({
height: navState.title
});
console.log("DATA");
console.log(this.state.height)
}
在我做的实际 WebView 渲染中:
<WebView style={this._setWebviewHeight()}
automaticallyAdjustContentInsets={false}
scrollEnabled={false}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
html={html}>
</WebView>
地点:
_setWebviewHeight() {
return {
height: this.state.height,
padding: 20,
}
}
在这种情况下,我遇到了错误,我无法通过状态获取内容的高度。那我该怎么办?
解决思路取自这里:React native: Is it possible to have the height of a html content in a webview?
【问题讨论】:
-
你得到什么错误?
标签: javascript webview reactjs react-native