injectedJavaScript doesnt seem to work on IOS
See original GitHub issueBug description: Setup the WebView and try to use the “injectedJavaScript” prop. It works as expected on Android but when on IOS it does nothing.
To Reproduce:
- Use this code below as your render method:
render() {
const runFirst = `
document.body.style.backgroundColor = 'red';
setTimeout(function() { window.alert('hi') }, 2000);
true; // note: this is required, or you'll sometimes get silent failures
`
return (
<View style={{ flex: 1 }}>
<WebView
source={{
uri: 'https://github.com/react-native-community/react-native-webview',
}}
injectedJavaScript={runFirst}
/>
</View>
)
}
Expected behavior: Expected to render the github page for react-native-webview with a red background on both platforms.
Screenshots/Videos: Android:
IOS:
Environment:
- OS: IOS
- OS version: 13.3
- react-native version: 0.62
- react-native-webview version: 9.0.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:14 (5 by maintainers)
Top Results From Across the Web
injectedJavaScript is not working in Webview of react native
Well, you have more than one issue here. First one is your web view needs to be wrapped in a containing View component...
Read more >Need help with react-native Webview, injecting react ... - Reddit
The string interpolation doesn't work. What should I do if I'm trying to pass data from react native into the javascript string that's...
Read more >why react native webview injectedJavascript doesn't work on ...
Coding example for the question why react native webview injectedJavascript doesn't work on IOS?-React Native.
Read more >Injecting JavaScript Into Web View In iOS - Swift Senpai
Learn how to inject JavaScript into the iOS web view (WKWebView) to customize the HTML styling to fit the look and feel of...
Read more >react-native-webview - npm
React Native WebView component for iOS, Android, macOS, and Windows. ... for "RNCWebView does not exist" it likely means you forgot to run...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
According to the guide, you now must pass a function as the
onMessage
prop for injected Javascript to work. But, it will work in Android without it anyway.I am already using ‘onMessage’. Still it is not working to inject javascript. My WebView something like that: <WebView onLoadEnd={() => { this._setstatus() }} onNavigationStateChange={this.on_navigaton_new} injectedJavaScript={custom_script} onMessage={x => this.onMessageGet(x)} javaScriptEnabled={true} source={{ uri: this.state.url, forceReload: this.state.forceReload }} allowsLinkPsreview={true} incognito={true} domStorageEnabled={true} ref={(ref) => this.myWebView = ref}/>