I am trying to load a local javascript into a react native webview but it seems that these changes that I want to make on the page are not taken effect, I think that there is some issues in the syntax , could you please correct my syntax
let injec= "document.querySelector('.para').style.color='blue';";
injec += "document.querySelector('#dicc').style.display='none';";
const test = "document.querySelectorAll('label');";
let labels = "Array.from(test) labels.forEach(function(lab) { lab.style.color = 'blue'});";
injec += labels;
<WebView
onNavigationStateChange={this.onNavigationStateChange}
style={webView}
renderError={this.handleRenderError}
onError={this.handleRenderError}
injectedJavaScript= {injec}
....
I am using webview like this and it works perfect for me. Try
...
render(){
...
const injectJS = "My_Js_Code";
return(
<View style={styles.container}>
<WebView style={styles.webView}
source={{uri: 'https://example.com/'}}
javaScriptEnabled={true}
domStorageEnabled={true}
startInLoadingState={true}
injectedJavaScript={injectJS}
/>
</View>
);
}
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.