0

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}
....

1 Answer 1

1

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>
    );
  }

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

2 Comments

the problem is in the content of Injected javascript , syntax is not correct , may be single quotes is missing or .. i dont know still testing
There are online tools for debug javascript code. Try them

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.