我无法将这个简单的js代码注入react-native webview。injectJavaScript在反应原生Webview中不工作
I referred this link also but no solution provided here.
Then I found this one which works for html props but not uri.
import React, { Component } from 'react';
import { Platform,
StyleSheet,
Text,
View,
WebView
} from 'react-native';
export default class App extends Component<{}> {
injectjs(){
let jsCode = 'alert(hello)';
return jsCode;
}
render() {
return <WebView
javaScriptEnabled={true}
injectedJavaScript={this.injectjs()}
source={{uri:"https://www.google.com"}} style={{ marginTop: 20 }} />;
}
}
不能工作。我尝试了很多格式。关于配置的一些细节:平台:Android 6,SDK:23/24,react-native版本:0.49.3。 –
当您在iOS/Android中运行react-native时,您能看到WebView吗?因为如果你看不到WebView,那么问题可能不是你的Javascript代码。 @KapilYadav –
我在这里发布的代码可以在webview中成功打开google.com或任何其他网站,但我看不到警报。如果我在源代码中使用HTML而不是URI,那么它将很好地工作。在你的设备上?@ Mateo Guzman。 –