美文网首页
RN webview 内地图有交互处理

RN webview 内地图有交互处理

作者: 旅途开发者 | 来源:发表于2022-05-12 09:32 被阅读0次

react native webview的实现方法

render() {
        return (<View>
           <WebView
                        //布尔值,指定WebView中是否启用JavaScript。只在Android上使用,因为在iOS上默认启用了JavaScript。
                        javaScriptEnabled={true}
                       //开启定位
                        geolocationEnabled={true}
                       //弹性
                        bounces={false}
                      //是否使用wkwebview
                        useWebKit={true}
                        style={{ flex: 1, }}
                        source={{ uri: 'https://www.baidu.com' }}
                        scalesPageToFit={true}
                    />
        </View>)
    }

只写上面的会展示webview,但是没办法获取到用户的详细定位,还需要在当前界面添加以下方法

javascriptToInject = () => {
        return `
          $(document).ready(function() {
            $('a').click(function(event) {
              if ($(this).attr('href')) {
                var href = $(this).attr('href');
                window.webView.postMessage('Link tapped: ' + href);
              }
            })
          })
        `
    }

相关文章

网友评论

      本文标题:RN webview 内地图有交互处理

      本文链接:https://www.haomeiwen.com/subject/obdsurtx.html