Reputation: 1392
I am trying to create a mobile app via Xamarin for Android which has a WebView that shows a website, problem is that normal buttons fire, but javascript events do not fire. I have enabled Javascript, but no luck.
Upvotes: 2
Views: 4073
Reputation: 113
Had a bit of trouble with this myself for anyone working on this. The below helped. https://www.oreilly.com/library/view/building-hybrid-android/9781449361907/ch04.html
My issue was I was expecting web javascript functionality from a default browser and had not call webView.SetWebChromeClient(new Android.Webkit.WebChromeClient()); Needs to be called in customer renderer
After this webview started performing at intended
Upvotes: 0
Reputation: 1392
How to enable javascript in your android webview include the following code in MainActivity.OnCreate:
localWebView.Settings.JavaScriptEnabled = true;
localWebView.Settings.DomStorageEnabled = true;
The first allows javascript to work, the second will allow values to be stored in your HTML/DOM.
Upvotes: 3
Reputation: 344
It is probably due to insecure content stuff that is introduced in lollipop.
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
webView.Settings.MixedContentMode = MixedContentHandling.AlwaysAllow;
Try adding these lines and see if that works.
Upvotes: 1