injectedJavaScript is not working in IOS
See original GitHub issueBug description: I am using “react-native-webview”: “^10.10.2”. I am using “injectedJavaScript” in webview, this property is working fine in android but not working in ios.
Code import React, { Component } from ‘react’; import { WebView } from ‘react-native-webview’
class App extends React.Component { constructor(props) { super(props);
}
componentDidMount(){
}
myScript = () =>
window.document.getElementsByTagName("header")[0].style.display = "none";
render() { return ( <WebView source={{ uri: “https://www.helpmefund.org/campaigns” }} injectedJavaScript={this.myScript()} /> ); } }
export default App;
Environment:
- OS:IOS
- OS version:14.2
- react-native version:0.63.3
- react-native-webview version:10.10.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
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 >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 >Need help with react-native Webview, injecting ...
I figured out the answer. It's really nuanced. Essentially you have to create a global window variable before the injectedJavascript() method is ...
Read more >React Native WebView: A complete guide
This package will work both on Android and iOS devices. ... Well, React Native WebView also offers a solution for this problem!
Read more >Tool shows JavaScript code injected via in-app browser
Developer creates tool that shows injected JavaScript commands through an ... these in-app browsers are based on Safari's WebKit on iOS, ...
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
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @sraza295 I was able to fix the issue I was having by adding:
onMessage={(event) => {}}
as a prop to the WebView. Solution found here: https://github.com/react-native-webview/react-native-webview/blob/4d8a76f3691479ef22b55e05c07921af99332395/docs/Guide.md under “Communicating between JS and Native”.Not sure why or when that became required because it definitely used to work without it. But perhaps that’s the solution for you as well.
I have the same issue, javascript isn’t being injected on iOS. I made sure to add
true;
to my script and includeonMessage