1

How can I pass props in Webview and get the props in my local html page

export default class HomeScreen extends React.Component {
  render() {
    return (
       <View>
            <WebView source={require('../Web/index.html')} />
          </View>  
    );
  }
}

1 Answer 1

1

You cannot pass any props to html page inside your Webview.

But there is a trick by using injectedJavascript https://facebook.github.io/react-native/docs/webview.html#injectedjavascript

Here is example: https://www.undefinednull.com/2015/12/27/injecting-custom-javascript-into-react-natives-webview/

Sign up to request clarification or add additional context in comments.

9 Comments

Yes i tried injectedJavascript it's working but i want to pass an dynamic object
what is the dynamic object ?
if here is the static object "window.static = 1;" you mentioned => injectedJavascript for your dynamic is `window.dynObj = ${JSON.stringify(your_dynObj)};`
let say if i have a function called jsonData() which returns an array of objects, how do we inject that ex:jsonData() { const items = [ { id: 1, title: "Thomas Williams" }, { id: 2, title: "Mary Spencer" } ] return document.querySelector('#query').value = ${JSON.stringify(items)} } <WebView source={require('../Web/index.html')} injectedJavaScript = {this.jsonData} />
what do you want to inject? that function definition or its returned value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.