React Native - open links in browser

前端 未结 13 712
遇见更好的自我
遇见更好的自我 2020-12-04 11:59

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.

13条回答
  •  误落风尘
    2020-12-04 12:46

    1. If you are attempting to open a redirect url and you get an error from an android intent such as "err_unknown_url_scheme".

    2. Check what it is trying to open because it may have detected android traffic and attempted to open in the corresponding app.

    3. If you wish for it to open in the webview anyway and you get an intent back from a redirect, intercept it in onNavigationStateChange and rewrite it:

    onNavigationStateChange={event => {
      if (event.url !== uri) {
          if (event.url.match('intent://')) {
              SetSearchClick(
                  event.url.replace('intent://', 'https://'),
              );
             }
       }
    }}
    
    

提交回复
热议问题