在WebView中,我添加了index.html
<WebView
source={{ uri: 'file:///android_asset/index.html' }}
startInLoadingState={true}
style={{ marginTop: 20, height: 100 }} />在index.html文件中
<!DOCTYPE html>
<html>
<header>
<link rel="stylesheet" href="./mathquill.css" />
<script src="./jquery.min.js"></script>
<script src="./mathquill.js"></script>
<script>
var MQ = MathQuill.getInterface(2);
</script>
</header>
<body>
<span id="problem">ax^2 + bx + c = 0</span>
<script>
var problemSpan = document.getElementById('problem');
MQ.StaticMath(problemSpan);
</script>
</body>
</html>我想知道如何与WebView通信以更改要显示的文本。
发布于 2017-08-17 17:16:18
找到解决方案了。
将此内容添加到index.html
document.addEventListener("message", function(data) {
...
}将WebView更改为
<WebView
ref={(webview) => this.webview = webview }
source={{ uri: 'file:///android_asset/index.html' }}
startInLoadingState={true}
style={{ marginTop: 20, height: 100 }}
/>并通过(我在componentDidMount中测试)发布数据
componentDidMount() {
this.webview.postMessage('message')
}https://stackoverflow.com/questions/45730008
复制相似问题