Sub Globals
'These global variables will be redeclared each time the activity is created.
Dim WebView1 As WebView
Dim WVE As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Initialize the WebView and WebViewExtras
WebView1.Initialize("WebView1")
WVE.Initialize(WebView1)
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
'Enable JavaScript
WVE.addJavascriptInterface(WebView1, "B4A")
'Load the URL
WebView1.LoadUrl("https://yourwebsite.com")
End Sub
Sub WebView1_PageFinished (Url As String)
' CSS to prevent highlighting of links on tap hold
Dim css As String
css = "a, a:active, a:focus { outline: none !important; -webkit-tap-highlight-color: rgba(0,0,0,0); }"
' JavaScript to prevent the default context menu (long press menu)
Dim js As String
js = "javascript:(function() {" & _
"document.body.style.webkitTouchCallout='none';" & _ ' Prevents the callout on long press
"document.body.style.webkitUserSelect='none';" & _ ' Prevents text selection
"var style = document.createElement('style');" & _
"style.type = 'text/css';" & _
"style.appendChild(document.createTextNode('" & css & "'));" & _
"document.head.appendChild(style);" & _
"var links = document.getElementsByTagName('a');" & _
"for(var i = 0; i < links.length; i++) {" & _
" links[i].addEventListener('touchstart', function(e) { e.preventDefault(); }, false);" & _
" links[i].addEventListener('touchend', function(e) { window.location = this.href; }, false);" & _
"}" & _
"})()"
WVE.executeJavascript(WebView1, js) 'Execute the JS and CSS after the page has loaded
End Sub