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

    }

  • 相关阅读:
    (译)linux系统关于命令echo的15个例子
    linux之grep实例讲解
    linux grep练习
    (译)"usermod"命令使用完全指导---15个练习例程截图
    linux分区,文件系统,目录结构概述
    Linux 配置YUM
    Linux 强制安装rpm 包
    $LANG、$NLS_LANG 记录一下
    Oracle性能诊断艺术-相关脚本说明
    datafile相关(add、rename、drop)
  • 原文地址:https://www.cnblogs.com/wgscd/p/7574851.html
Copyright © 2011-2022 走看看