• 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" });
        }
    }
    

    }

  • 相关阅读:
    Good Vegetable 4级算法题 分值: [320/3120] 问题: [8/78]
    Bitwise And Queries
    XD
    补题0%……计划进行中
    PC网页版、移动客户端、Wap版 有什么不同
    关于"软件评测师"
    POSTMAN-REST Client
    【NO.13】Jmeter
    【NO.12-1】Jmeter
    【NO.11】Jmeter
  • 原文地址:https://www.cnblogs.com/wgscd/p/7574851.html
Copyright © 2020-2023  润新知