Android Question Javascript not loading/running in WebView

biometrics

Active Member
Licensed User
I have a web page that loads a Javascript .js library. It works correctly with browsers on Windows (Firefox) or Android (Chrome). It's not loading in a WebView.

I've added Javascript alert statements in the Javascript in the HTML and in the .js libraries as a test.

I can see it's working on Windows and Android based on the Alerts being displayed.

But in the WebView only the Javascript alert in the HTML display, the one in the .js file doesn't.

The .js library is loaded into HTML in the usual way:

html
B4X:
<script type="text/javascript">
alert("This displays");
</script>

<script type="text/javascript" src="library.js"></script>
library.js
B4X:
alert("This does NOT display");
app
B4X:
#Region  Project Attributes
   #ApplicationLabel: WebView Javascript
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals

End Sub

Sub Globals
   Dim libWebView As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   libWebView.Initialize("libWebView")
   Activity.AddView(libWebView, 0, 0, 100%X, 100%Y)
   libWebView.LoadUrl("https://xxxxxxxxxxxx")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
So, any ideas why the .js isn't loading?
 

Brandsum

Well-Known Member
Licensed User
Add webchromeclient using webviewextra and check the console logs for any JavaScript error.
 

drgottjr

Well-Known Member
Licensed User
works if you add:
B4X:
dim wvx as WebViewExtras
wvx.addWebChromeClient( libWebView, "wvx")
as suggested above.
no problem with your .html and .js files on my server. 2 alerts pop up as expected on my nexus.
 

biometrics

Active Member
Licensed User
Thanks everyone. On preparing a test app and webpage to upload here the Javascript stopped working completely. Adding the ChromeClient fixed it.

Which is weird as I originally had the problem with a larger app (which is using the ChromeClient) and website and I was trying to recreate it in a test app.

Anyway, so something else is going on...
 
Top