so, it does work. at least on a simple test. here's the deal with alert() and webview: by default, webview does not show alerts. in order to enable alerts, you have to add the webviewextras.addWebChromeClient() method. of course, by not adding webviewextras.addWebChromeClient(), you may miss out on other things, but at least you won't see alerts.
second, if you do use webviewextras.addWebChromeClient(), then the javascript interface is necessary. when you inject the necessary javascript to disable alerts, it will disable them,
but there will be a small error thrown to your b4a log. the user will not see this, nor will she see the alert.
please add the attached "alert.txt" sample to your Files folder (and inform the IDE). it's test html page, but due to security reasosns, we're not allowed to upload it as such; we have to change the name. you can leave it as ".txt"; webview doesn't care or know. also had the following snippets to your project:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim webview As WebView
Dim wvx As WebViewExtras
Dim btn As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
webview.Initialize("wv")
Activity.AddView(webview, 0%x,0%y,100%x,100%y)
wvx.addJavascriptInterface(webview, "jsi")
' wvx.addWebChromeClient(webview, "cc")
btn.Initialize("btn")
Activity.AddView(btn, 80%x, 80%y, 15%x, 10%y)
btn.Text = "tap me"
webview.LoadHtml( File.ReadString( File.DirAssets, "alert.html"))
btn.BringToFront
End Sub
Sub btn_Click
wvx.executeJavascript( webview, "window.alert=''" )
End Sub
what should happen (at least it happens when i run it on my device) is the follow: a webview will appear with a tiny button telling you to click it. at the bottom of the webview there will be another bottom that says "tap me". the button at the top is in the html document loaded by the webview. the bottom at the bottom is a b4a button view.
tap the button at the top. there should be no alert. tap it again if you like. there should be no alert. no need to tap the button at the bottom, since there is no alert in any case.
now, go to the line in the b4a project that has commented out the addition of chromeclient:
' wvx.addWebChromeClient(webview, "cc")
uncomment the line, thus activing alert
recompile and run the project. tap on the top button. you should now see an alert. tap again. alert.
now tap on the bottom button to inject the disabling javascript into the webview page.
now tap the button at the top again. alert gone. BUT there will be an error in the log.
note: pay close attention to the injected javascript. it's 2 single quotes inside a pair of double quotes:
wvx.executeJavascript( webview, "window.alert=''" )