Hi i am using react native\'s webview to display some html, i want that whenever a user clicks a link inside that html, it will open the user\'s browser with that link.
{
this.webView.ref = webView;
}}
onNavigationStateChange={(navState) => {
this.webView.canGoBack = navState.canGoBack;
if (!navState.url.includes('yourdomain.com')) {
Linking.openURL(navState.url);
return false;
}
}}
onShouldStartLoadWithRequest={(event) => {
if (!event.url.includes('yourdomain.com')) {
Linking.openURL(event.url);
return false;
}
return true;
}}
style={{flex: 1}}
startInLoadingState={true}
renderLoading={() => {
return (
);
}}
/>
I struggled with this one, my use case was to open external links in a separate browser. This solution worked for me.