简体   繁体   中英

Unable to call a button click function within a webview in react native

I am trying to call webview button click function on my own button click function but nothing seems to work. My code is similar to this

buttonClick = () => {
  
this.webview.injectJavaScript(`document.getElementById('webBtn').click()`);
}

redner(){

return(
<View>

 <WebView
            source={{uri: 'https://mywebsite.com'}}

          />

<TouchableOpacity onPress={() => this.buttonClick()}><Text> Click here </Text></TouchableOpacity>
</View>
)

}

I have tried the same Method with javascript It works Perfect there but I don't why its creating issues with the WebView in react Native . Any help would be Appreciated.

The ref of the WebView was not specified.

<WebView      
    ref={(ref)=>{this.webview=ref;}}
    source={{uri: 'https://mywebsite.com'}}    
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM