public VideoPage(string source) { Source = source; InitializeComponent(); SetUseNativePlayer(); if (UseWebPlayer) { VideoPlayerView.IsEnabled = false; VideoPlayerView.IsVisible = false; VideoWebView = new FormsWebView(); VideoWebView.Source = "video.html"; VideoWebView.ContentType = Xam.Plugin.WebView.Abstractions.Enumerations.WebViewContentType.LocalFile; VideoStack.Children.Add(VideoWebView); VideoWebView.OnContentLoaded += VideoWebView_OnContentLoaded; VideoWebView.AddLocalCallback("RaiseEndedEvent", LoadNextVideo); } ViewModel = new VideoPageViewModel(); this.BindingContext = ViewModel; }
public async override void DidFinishNavigation(WKWebView webView, WKNavigation navigation) { if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer)) { return; } if (renderer.Element == null) { return; } renderer.Element.HandleNavigationCompleted(webView.Url.ToString()); await renderer.OnJavascriptInjectionRequest(FormsWebView.InjectedFunction); if (renderer.Element.EnableGlobalCallbacks) { foreach (var function in FormsWebView.GlobalRegisteredCallbacks) { await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(function.Key)); } } foreach (var function in renderer.Element.LocalRegisteredCallbacks) { await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(function.Key)); } renderer.Element.CanGoBack = webView.CanGoBack; renderer.Element.CanGoForward = webView.CanGoForward; renderer.Element.Navigating = false; renderer.Element.HandleContentLoaded(); }
public MainPage() { try { InitializeComponent(); FormsWebView fwv = new FormsWebView(); fwv.Source = digiview.Helper.SettingsHelper.GetPath(); fwv.IsVisible = true; fwv.MinimumWidthRequest = 200; fwv.MinimumHeightRequest = 200; fwv.HorizontalOptions = LayoutOptions.FillAndExpand; fwv.VerticalOptions = LayoutOptions.FillAndExpand; fwv.EnableGlobalHeaders = true; fwv.OnContentLoaded += this.Fwv_OnContentLoaded; ((digiview.App)App.Current).SetWebView(fwv); this.web_grid.Children.Add(fwv); Models.Sync.SyncModel.GetInstance().Start(); } catch (TimeoutException te) { Console.WriteLine(te.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
public JavascriptSample() { InitializeComponent(); InjectionText.Text = "document.body.style.backgroundColor = \"red\";"; GlobalText.Text = "globalCallback('Hello from Javascript!');"; LocalText.Text = "localCallback('Hello from Javascript!');"; FormsWebView.AddGlobalCallback("globalCallback", GlobalCallback); WebContent.AddLocalCallback("localCallback", LocalCallback); }
public JavascriptString() { InitializeComponent(); WebContent.Source = "<!doctype html><html><head></head><body><h1>String Data Example</h1></body></html>"; InjectionText.Text = "document.body.style.backgroundColor = \"red\";"; GlobalText.Text = "globalCallback('Hello from Javascript!');"; LocalText.Text = "localCallback('Hello from Javascript!');"; FormsWebView.AddGlobalCallback("globalCallback", GlobalCallback); WebContent.AddLocalCallback("localCallback", LocalCallback); }
public async override void OnPageFinished(Android.Webkit.WebView view, string url) { if (Reference == null || !Reference.TryGetTarget(out FormsWebViewRenderer renderer)) { return; } if (renderer.Element == null || (view as WebViewEx).Disposed) { return; } // Add Injection Function await renderer.OnJavascriptInjectionRequest(FormsWebView.InjectedFunction); if (renderer?.Element == null || (view as WebViewEx).Disposed) { return; } // Add Global Callbacks if (renderer.Element.EnableGlobalCallbacks) { foreach (var callback in FormsWebView.GlobalRegisteredCallbacks) { await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(callback.Key)); } } // Add Local Callbacks foreach (var callback in renderer.Element.LocalRegisteredCallbacks) { await renderer.OnJavascriptInjectionRequest(FormsWebView.GenerateFunctionScript(callback.Key)); } if (renderer?.Element == null || (view as WebViewEx).Disposed) { return; } renderer.Element.CanGoBack = view.CanGoBack(); renderer.Element.CanGoForward = view.CanGoForward(); renderer.Element.Navigating = false; renderer.Element.HandleNavigationCompleted(url); renderer.Element.HandleContentLoaded(); }
public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation) { Renderer.InjectJS(WebViewControlDelegate.InjectedFunction); foreach (var key in Element.GetLocalCallbacks()) { Renderer.InjectJS(WebViewControlDelegate.GenerateFunctionScript(key)); } foreach (var key in FormsWebView.GetGlobalCallbacks()) { Renderer.InjectJS(WebViewControlDelegate.GenerateFunctionScript(key)); } Element.InvokeEvent(WebViewEventType.NavigationStackUpdate, new NavigationStackUpdateDelegate(Element, Renderer.Control.CanGoBack, Renderer.Control.CanGoForward)); Element.InvokeEvent(WebViewEventType.ContentLoaded, new ContentLoadedDelegate(Element, webView.Url.AbsoluteUrl.ToString())); }
public App() { var htmlString = @" <html> <head> <meta charset='utf-8'/> </head> <body> <h1>Title</h1> <a href='http://www.google.com'>google</a> </body> </html> "; FormsWebView wv = new FormsWebView(); wv.ContentType = Xam.Plugin.Abstractions.Enumerations.WebViewContentType.StringData; wv.Source = htmlString; wv.HeightRequest = 500.0; wv.WidthRequest = 500.0; label.Text = "Initial"; // The root page of your application var content = new ContentPage { Title = "lastCalendar", Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Red, Children = { label, wv } } }; wv.OnNavigationStarted += Wv_OnNavigationStarted; //content.Appearing += Content_Appearing; MainPage = new NavigationPage(content); }
public override void OnPageFinished(Android.Webkit.WebView view, string url) { Element.InvokeEvent(WebViewEventType.NavigationComplete, new NavigationCompletedDelegate(Element, url, true)); Renderer.InjectJavascript(WebViewControlDelegate.InjectedFunction); foreach (var key in FormsWebView.GetGlobalCallbacks()) { Renderer.InjectJavascript(WebViewControlDelegate.GenerateFunctionScript(key)); } foreach (var key in Element.GetLocalCallbacks()) { Renderer.InjectJavascript(WebViewControlDelegate.GenerateFunctionScript(key)); } Element.InvokeEvent(WebViewEventType.NavigationStackUpdate, new NavigationStackUpdateDelegate(Element, Renderer.Control.CanGoBack(), Renderer.Control.CanGoForward())); Element.InvokeEvent(WebViewEventType.ContentLoaded, new ContentLoadedDelegate(Element, url)); base.OnPageFinished(view, url); }
public WebPage() { Instance = this; InitializeComponent(); On <iOS>().SetUseSafeArea(true); webSpeaker = WebSpeaker.Instance; webSpeaker.SetWebView(WebContent); // 加载帮助文档 WebContent.ContentType = WebViewContentType.LocalFile; WebContent.Source = "index.html"; WebContent.OnContentLoaded += WebContent_OnContentLoaded; WebView = WebContent; }
private void Button_Clicked(object sender, EventArgs e) { count = count + 1; Debug.WriteLine($"Button Clicked, Count = {count}"); stack.Children.Clear(); FormsWebView wv3 = new FormsWebView() { Source = htmlString(count.ToString()), ContentType = Xam.Plugin.Abstractions.Enumerations.WebViewContentType.StringData, BackgroundColor = Color.Red, HeightRequest = 300.0, WidthRequest = 300.0 }; //wv3.RemoveAllLocalCallbacks(); //wv3.RemoveAllGlobalCallbacks(); wv3.RegisterLocalCallback("test", s => { Debug.WriteLine($"from {count}: " + s); }); wv3.OnContentLoaded += Wv3_OnContentLoaded; wv3.OnNavigationStarted += Wv3_OnNavigationStarted; stack.Children.Add(wv3); }
public MainPage() { InitializeComponent(); //SampleWebView.Source= "http://169.254.80.80:8080/bonita/loginservice?redirectUrl=portal%2Fhomepage&username=walter.bates&password=bpm" ; SampleWebView.Source = "http://169.254.80.80:3000/Home/About"; FormsWebView.AddGlobalCallback("InvokeFunction", async(p) => { var person = JsonConvert.DeserializeObject <Person>(p); await DisplayAlert("InvokeFunction", person.Name + person.Password, "OK"); // var argument = JsonConvert.SerializeObject(person); // await SampleWebView.InjectJavascriptAsync("InvokeFunctionReturnData('" + argument + "')"); }); SampleWebView.AddLocalCallback("InvokeFunction", async(p) => { var person = JsonConvert.DeserializeObject <Person>(p); await DisplayAlert("InvokeFunction", person.Name + person.Password, "OK"); // var argument = JsonConvert.SerializeObject(person); // await SampleWebView.InjectJavascriptAsync("InvokeFunctionReturnData('" + argument + "')"); }); execute.Clicked += Execute_Clicked; }
public App() { WebView = new FormsWebView() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Uri = "https://www.xamarin.com" }; WebView.RegisterCallback("test", (str) => { Debug.WriteLine(str); }); // The root page of your application var content = new ContentPage { Title = "SampleApp", Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Red, Children = { WebView } } }; WebView.NavigationStarted += OnNavigationStarted; WebView.NavigationCompleted += OnNavigationComplete; WebView.OnJavascriptResponse += OnJavascriptResponse; content.Appearing += Content_Appearing; MainPage = new NavigationPage(content); }
protected WebViewDelegate(FormsWebView sender) { Sender = sender; }
public JavascriptResponseDelegate(FormsWebView element, string data) : base(element) { Data = data; }
public void SetWebView(FormsWebView webview) { this.web_content = webview; }
public NavigationStackUpdateDelegate(FormsWebView sender, bool canGoBack, bool canGoForward) : base(sender) { CanGoBack = canGoBack; CanGoForward = canGoForward; }
public NavigationCompletedDelegate(FormsWebView element, string uri, bool isSuccess = true) : base(element) { Uri = uri; IsSuccess = isSuccess; }
public NavigationErrorDelegate(FormsWebView sender, int errorCode) : base(sender) { ErrorCode = errorCode; }
internal void InjectJavascript(FormsWebView sender, string js) { OnInjectJavascriptRequest?.Invoke(sender, js); }
public void NotifyCallbacksChanged(FormsWebView sender, string key, bool isGlobal) { OnActionAdded?.Invoke(sender, key, isGlobal); }
public App() { WebView = new FormsWebView() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, ContentType = WebViewContentType.Internet, Source = "https://www.xamarin.com" }; /* * Uncomment to use HTML data * WebView = new FormsWebView() * { * VerticalOptions = LayoutOptions.FillAndExpand, * HorizontalOptions = LayoutOptions.FillAndExpand, * ContentType = WebViewContentType.StringData, * Source = "<html><body><h1>Hello World!</h1></body></html>" * }; */ /* * Uncomment to use local file * WebView = new FormsWebView() * { * VerticalOptions = LayoutOptions.FillAndExpand, * HorizontalOptions = LayoutOptions.FillAndExpand, * ContentType = WebViewContentType.LocalFile, * Source = "Sample.html" * }; */ WebView.RegisterCallback("test", (str) => { Debug.WriteLine(str); }); // The root page of your application var content = new ContentPage { Title = "SampleApp", Content = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.Red, Children = { WebView } } }; WebView.OnNavigationStarted += OnNavigationStarted; WebView.OnNavigationCompleted += OnNavigationComplete; WebView.OnContentLoaded += OnContentLoaded; WebView.OnJavascriptResponse += OnJavascriptResponse; content.Appearing += Content_Appearing; MainPage = new NavigationPage(content); }
public NavigationRequestedDelegate(FormsWebView element, string uri) : base(element) { Uri = uri; }
public FormsWKNavigationDelegate(FormsWebViewRenderer renderer, FormsWebView element) { Renderer = renderer; Element = element; }
public ContentLoadedDelegate(FormsWebView element, string uri) : base(element) { Uri = uri; }
public void PerformNavigation(FormsWebView sender, string uri, WebViewContentType contentType) { OnNavigationRequestedFromUser?.Invoke(sender, uri, contentType); }
public void SetWebView(FormsWebView webView) { this.webView = webView; }
internal void NavigateThroughStack(FormsWebView sender, bool forward) { OnStackNavigationRequested?.Invoke(sender, forward); }
public FormsWebViewClient(FormsWebView element, FormsWebViewRenderer renderer) { Element = element; Renderer = renderer; }