locked
Enable Javascript on WebView RRS feed

  • Question

  • User31568 posted

    Hi,

    I am using this to show a LiveStream from uStream (IBM):

    var htmlSource = new HtmlWebViewSource();
    
    StringBuilder html = new StringBuilder();
    
    html.AppendLine("<html>");
    html.AppendLine("<body>");
    html.AppendLine("<iframe src='");
    html.AppendLine(streaming_url);
    html.AppendLine("' style='border: 0;' webkitallowfullscreen allowfullscreen frameborder='no' width='100%' height='100%'>");
    html.AppendLine("</iframe>");
    html.AppendLine("</body>");
    html.AppendLine("</html>");
    
    htmlSource.Html = html.ToString();
    

    so if you use this URL from IBM:

    https://www.ustream.tv/embed/1524

    as a test you'll see that you can't interact with the player buttons, e.g. Fullscreen which I guess it's a JavaScript problem

    How can i fix this please?

    Thanks, Jassim

    Tuesday, October 15, 2019 5:11 AM

All replies

  • User369978 posted

    In Android , WebView will block the JavaScript in default . And you can enable it by using Custom Renderer .

    ``` using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Webkit; using Android.Widget;

    using xxx; using xxx.Droid;

    using Xamarin.Forms; using Xamarin.Forms.Platform.Android;

    [assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MyWebViewRenderer))] namespace xxx.Droid { public class MyWebViewRenderer:WebViewRenderer { public MyWebViewRenderer(Context context):base(context) {

        }
    
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);
    
            if(Control!=null)
            {
    
                Android.Webkit.WebView webview =(Android.Webkit.WebView) Control;
                WebSettings settings = webview.Settings;
    
    
                settings.JavaScriptEnabled = true;
    
            }
    
        }
    
    }
    

    } ```

    Tuesday, October 15, 2019 2:48 PM