0

i try to injectJavaScript in react native web view like bellow work well

setTimeout(() => {
 this.webref.injectJavaScript(someJSCODE); 
}, 3000);
<WebView
ref={r => this.webref = r}
source={{uri: 'https://accounts.google.com/'}}
 />

but if i call r.injectJavaScript(someCode) it not working.

<WebView
ref={r => r.injectJavaScript(somecode)}
source={{uri: 'https://accounts.google.com/'}}
 />
vy.pham
  • 571
  • 6
  • 20

1 Answers1

0

Can you try the following ,

...
<WebView
        source={{
          uri: "https://************.org/privacy-policy/"
        }}
        ref={WEBVIEW_REF => (this.WebViewRef = WEBVIEW_REF)}
        javaScriptEnabled={true}
        injectedJavaScript={
          "document.getElementsByClassName('site-content')[0].style.paddingTop='0px',document.getElementsByClassName('header')[0].style.display='none', document.getElementsByClassName('footer')[0].style.display='none',document.getElementsByClassName('subscribe-line')[0].style.display='none'"
        }
        onLoadProgress={e => this._onLoading(e.nativeEvent.progress)}
      />
...
Jebin Benny
  • 933
  • 1
  • 5
  • 9