2

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.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.