zoukankan      html  css  js  c++  java
  • UWP Test Webview JS interact, new window open (新窗口打开)

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices.WindowsRuntime;
    using Windows.Foundation;
    using Windows.Foundation.Collections;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Controls.Primitives;
    using Windows.UI.Xaml.Data;
    using Windows.UI.Xaml.Input;
    using Windows.UI.Xaml.Media;
    using Windows.UI.Xaml.Navigation;
    using Newtonsoft.Json;
    using System.Net.Http;
    using System.Net;
    // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

    namespace App1
    {
    ///


    /// An empty page that can be used on its own or navigated to within a Frame.
    ///

    public sealed partial class MainPage : Page
    {
    public MainPage()
    {
    this.InitializeComponent();
    this.Loaded += MainPage_Loaded;
    web.NewWindowRequested += Web_NewWindowRequested;//新窗口打开事件
    }

        private void Web_NewWindowRequested(WebView sender, WebViewNewWindowRequestedEventArgs args)
        {
            args.Handled = true;//
            if (args.Uri != null && args.Uri.ToString() != "") {
                new MessageDialog(""+ args.Uri, "tttt").ShowAsync();
            }
        }
    
    
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            web.NavigateToString("<html><title>ttt</title><body><br/><br/><br/><br/><div id='t' style='font-size:25px;color:red;'>7777</div>test<script type='text/javascript'>alert(99);window.external.notify('hello');function test(s){t.innerText=s;}</script></body></html>");
        }
    
        private async void  web_ScriptNotify(object sender, NotifyEventArgs e)
        {
            var dialog = new ContentDialog()
            {
                Title = "????",
                Content = ""+e.Value,
                PrimaryButtonText = "??",
                SecondaryButtonText = "??",
                FullSizeDesired = false,
            };
    
           // dialog.PrimaryButtonClick += (_s, _e) => { loading.Visibility = Visibility.Visible; };
            await dialog.ShowAsync();
    
        }
    
        private async  void Button_Click(object sender, RoutedEventArgs e)
        {
            var x = web.InvokeScriptAsync("test", new string[] {"5555555" });
        }
    }
    

    }

  • 相关阅读:
    UVALive 6909 Kevin's Problem 数学排列组合
    UVALive 6908 Electric Bike dp
    UVALive 6907 Body Building tarjan
    UVALive 6906 Cluster Analysis 并查集
    八月微博
    hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
    hdu 5792 World is Exploding 树状数组
    hdu 5791 Two dp
    hdu 5787 K-wolf Number 数位dp
    hdu 5783 Divide the Sequence 贪心
  • 原文地址:https://www.cnblogs.com/wgscd/p/7574851.html
Copyright © 2011-2022 走看看