react-native-webview网页拨打电话

问题描述

在使用ReactNative开发过程中,使用了WebView来加载公司的市场宣传网页,并且在页面上设置了手机号<a>标签,但是在应用中点击网页上的这个链接后,报错“net::ERR_UNKNOWN_URL_SCHEME”

tel://11011112222

 

环境说明

react-native-webview版本号:9.3.0

解决方法

设置Webview的onNavigationStateChange函数,当其为“tel://”协议时,使用Linking跳转,并且返回false拦截webview的默认动作,参考资料见github(https://github.com/react-native-community/react-native-webview/issues/1084

render(){
  return(
    <WebView
      {...this.props}
      onShouldStartLoadWithRequest={this.onShouldStartLoadWithRequest}
    />
  )
}


/** ... 其他代码内容*/

/**
  *
  * @param request
  * @return {boolean} true:webView会继续加载默认动作,false:终止此次webView的加载动作
  */
onShouldStartLoadWithRequest = (request) => {
  let url = request.url
  if (url.startsWith('tel:')) {
    Linking.canOpenURL(url).then((enable) => {
      Linking.openURL(url).then(value => {
        console.log('openUrl ', value)
      })
    })
    return false
  }
  return true
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值