I try to call a function from injectedJavascript of webview , in android it works fine , but on IOS it didn't work , could you help me on that , this is my webview :
<View style={container}>
<WebView
javaScriptEnabled={true}
domStorageEnabled={true}
injectedJavascript={this.jsCode.bind(this)}
onNavigationStateChange={this.onNavigationStateChange}
source={webapp}
ref="WEBVIEW_REF"
style={webView}
decelerationRate="fast"
/>
</View >
my function is :
jsCode() {
let linn ='document.querySelector(".spl-bg2").style.color="blue";';
return linn;
}
injectedJavaScript is supposed to be a string that gets evaluated as javascript when the WebView loads so in your case it should work like this
let linn ='document.querySelector(".spl-bg2").style.color="blue";';
return(
<View style={container}>
<WebView
javaScriptEnabled={true}
domStorageEnabled={true}
injectedJavaScript ={linn}
onNavigationStateChange={this.onNavigationStateChange}
source={webapp}
ref="WEBVIEW_REF"
style={webView}
decelerationRate="fast"
/>
</View>)
Update
This is a working example of the above, that runs on a website and changes the colour of the first paragraph it finds:
https://snack.expo.io/rJHiavAwX
Have a look at it and maybe you will find your issue. Note that the prop name is injectedJavaScript and not injectedJavascript as you have it in your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With