private async void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) { if (MyWebView != null) { await MyWebView.InvokeScriptAsync("eval", new string[] { "ZoomFunction(" + e.NewValue.ToString() + ");" }); } }
private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { LoadingProgressBar.Visibility = Visibility.Collapsed; if (!args.IsSuccess) { ContentDialog d = new ContentDialog(); d.Title = "Oops"; d.Content = "Navigation to " + args.Uri.ToString() + " failed. " + args.WebErrorStatus.ToString(); d.PrimaryButtonText = "Ok"; await d.ShowAsync(); } if (this.isLoaded) { string m = args.Uri.Scheme + "://" + args.Uri.AbsolutePath; if (m != "ms-appx-web:///landingpage.html" && !this.isLoadedCompleted) { this.isLoadedCompleted = true; this.settings.AddToHistory(new SavedLink() { DocumentTitle = MyWebView.DocumentTitle, Url = args.Uri.ToString() }); } // Check for the landing page so that the user doesn't have to press // back an extra time if (m == "ms-appx-web:///landingpage.html") { if (this.Frame.CanGoBack) { this.Frame.GoBack(); } } } // Inject <F5>, <CTRL + R> support for refreshing // <ALT + LEFT_ARROW> support to go back string js = @"window.addEventListener('keydown', function(event) {if (event.key === 'F5') { location.reload(true); } else if (event.ctrlKey && event.key === 'r') { location.reload(true); } else if (event.altKey && event.key === 'Left') { window.history.back(); } }, false);"; if (settings.IsKeyboardShortcutsEnabled) { await MyWebView.InvokeScriptAsync("eval", new string[] { js }); } }
public void InvokeJSScript(string scriptName, string[] parameters) { //retrieves the UI thread and invokes javascript on this thread CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { MyWebView.InvokeScriptAsync(scriptName, parameters); }); }
private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { // Inject our Keydown handler into the page string inject = @"document.addEventListener('keydown', function(event) { window.external.notify('KeyDown:' + event.which); });"; await MyWebView.InvokeScriptAsync("eval", new List <string>() { inject }); }
private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { if (args.IsSuccess == true) { // need to set the window.utils.windowsApp property to true so that the document will be // loaded using the efficient windows local file part retriever MyWebView.InvokeScriptAsync("eval", new string[] { "window.utils.windowsApp = true;" }); } }
private async void TabContent_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals(nameof(Settings.ColorMode), StringComparison.Ordinal)) { ApplyUiColors(); } _handleSettingsArgs[0] = GetSettings(); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await MyWebView.InvokeScriptAsync("handle_settings", _handleSettingsArgs); }); }
private async void WebView_ScriptNotify(object sender, NotifyEventArgs e) { string[] urlParts = e.Value.Split('?'); string docLocation = urlParts[0]; Uri docUri = new Uri("ms-appx:///" + docLocation); var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(docUri); var props = await file.GetBasicPropertiesAsync(); var fileSize = props.Size; string range = urlParts[1]; string[] rangeParts = range.Split('&'); string originalRangeStart = rangeParts[0]; ulong rangeStart; // if the range start is negative then read from the end of the file if (originalRangeStart.StartsWith("-")) { ulong rangeStartPositive = (ulong)Math.Abs(Convert.ToInt64(originalRangeStart)); rangeStart = fileSize - rangeStartPositive; } else { rangeStart = Convert.ToUInt64(originalRangeStart); } // if the end range is not specified then it goes to the end of the file ulong rangeEnd = (rangeParts[1].Length == 0) ? fileSize : Convert.ToUInt64(rangeParts[1]); var stream = await file.OpenReadAsync(); stream.Seek(rangeStart); // get the number of bytes to read uint count = (uint)(rangeEnd - rangeStart); var bytes = new byte[count]; using (var dataReader = new DataReader(stream)) { await dataReader.LoadAsync(count); dataReader.ReadBytes(bytes); } string successFunction = string.Format("setTimeout(function() {{ window.CoreControls.PartRetrievers.WinRTPartRetriever.partSuccess('{0}', '{1}'); }}, 0);", Convert.ToBase64String(bytes), originalRangeStart); MyWebView.InvokeScriptAsync("eval", new string[] { successFunction }); }
private async void MyWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { string functionString = @"var nodeList = document.getElementsByTagName ('link'); for (var i = 0; i < nodeList.length; i++) { if ((nodeList[i].getAttribute('rel') == 'icon') || (nodeList[i].getAttribute('rel') == 'shortcut icon')) { favicon = nodeList[i].getAttribute('href'); window.external.notify(favicon); } }"; await MyWebView.InvokeScriptAsync("eval", new string[] { functionString }); }
private async void MyWebView_LoadCompleted(object sender, NavigationEventArgs e) { string functionString = @"var anchors = document.querySelectorAll('a'); for (var i = 0; i < anchors.length; i += 1) { anchors[i].oncontextmenu = function (e) { var e = e||window.event; var oX = e.clientX; var oY = e.clientY; var href = this.getAttribute('href'); window.external.notify([oX.toString(), oY.toString(), href].toString()); }; }"; await MyWebView.InvokeScriptAsync("eval", new string[] { functionString }); }
private async void scrollToPar(int par) { //double duration = _soundPosList[_curParagraph + 1] - _soundPosList[_curParagraph]; _scrollArgs[0] = par.ToString(inv); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { if (!_initialParagraphSelected) { _initialParagraphSelected = true; await MyWebView.InvokeScriptAsync("restore_pos", _scrollArgs); } else { await MyWebView.InvokeScriptAsync("scroll_to_par", _scrollArgs); } }); }
private async void Page_SizeChanged(object sender, SizeChangedEventArgs e) { var bounds = ApplicationView.GetForCurrentView().VisibleBounds; var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; var size = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor); if (size.Width < 1000 || size.Height < 600) { string[] script = new string[] { @" document.getElementById('pac-input').style.marginLeft='175px'; document.getElementById('pac-input').style.width='280px'; " }; try { await MyWebView.InvokeScriptAsync("eval", script); } catch (Exception ex) { } } else { string[] script = new string[] { @" document.getElementById('pac-input').style.marginLeft='250px'; document.getElementById('pac-input').style.width='400px'; " }; try { await MyWebView.InvokeScriptAsync("eval", script); } catch (Exception ex) { } } (this.DataContext as ViewModels.StartPageViewModel).PageSizeChanged(sender, e); }
private async void ScrollDown_Click(object sender, RoutedEventArgs e) { await MyWebView.InvokeScriptAsync("ScrollDownBtn", null); }
private async void HardwareButtons_CameraPressed(object sender, CameraEventArgs e) { await MyWebView.InvokeScriptAsync("eval", new string[] { "location.reload(true);" }); }