Android Question webview(show text) - copy and paste

kisoft

Well-Known Member
Licensed User
Longtime User
Hello. I use webview to show text. When the user scrolls the text sometimes the copy fields appear, paste. How to block this behavior?
 
  1. If you are using loadhtml to show text then you can prevent text selection via some CSS.
  2. If you are showing a webpage and you have access to that page content then you can prevent text selection via CSS or javascript.
  3. If you are showing a webpage and you don't have access to that page content then you can use WebViewExtra to execute javascript to prevent text selection.
If you don't know how to do that in css or javascript then tell me which one you need I'll post sample css or javascript code.
 
Upvote 0
Then just add this css inside head tag of that html file.
HTML: Copy
<style>
* {
   -webkit-user-select: none;
}
</style>

Though this following code sample will work for all the cases (local and remote webpage).
Code: Copy
Private wve As WebViewExtras
wve.Initialize(webview1)
wve.JavaScriptEnabled = True
wve.LoadUrl(xui.FileUri(File.DirAssets, "elem2.html"))

Sub webview1_PageFinished (Url As String)
    wve.ExecuteJavascript("document.querySelector('*').style.webkitUserSelect = 'none';")
End Sub
 
Upvote 0
Ok, thank you so much for this example. It will be a bit problematic for me, I use over 1000 html files in the project
 
Upvote 0
Back
Top