【问题标题】:react-native-webview disable text selectionreact-native-webview 禁用文本选择
【发布时间】:2021-02-09 13:55:04
【问题描述】:

有没有一种实用的方法来禁用 react-native webview 中的文本选择? 我想为用户禁用此example,这意味着用户将无法选择应用程序中显示的 webview 的文本。 我还需要保持链接能够按下并从中导航。

react-native-webview 中没有可以使用的 props。

无法访问我在 webview 中获取 html 的服务器。

【问题讨论】:

    标签: android ios reactjs react-native react-native-webview


    【解决方案1】:

    使用注入的Javascript禁用文本选择

    const INJECTEDJAVASCRIPT = "document.body.style.userSelect = 'none'";
    <WebView
      ...
      injectedJavaScript={INJECTEDJAVASCRIPT}
      ...
    />
    

    另一种方法是将您的 webview 包装在 View Tag 中

    <View pointerEvents="none">
      <WebView
        source={{ uri: webviewUrl }}
        scrollEnabled={false}
      />
    </View>
    

    【讨论】:

    猜你喜欢
    • 2017-04-12
    • 2018-01-18
    • 2017-08-10
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    相关资源
    最近更新 更多