RN webview 内地图有交互处理

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);
              }
            })
          })
        `
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。