• WPF和WebBrowser JS交互


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using WebKit;
    using System.Net;
    using System.Xml;
    namespace ZhenaiTool
    {
        /// <summary>
        /// Interaction logic for Window2.xaml
        /// </summary>
        public partial class Window2 : Window
        {
            public Window2()
            {
               InitializeComponent();
               OprateBasic OBasic=new OprateBasic(this);
               web.ObjectForScripting = OBasic;
                web.Url = new Uri("http://www.baidu.com");
               Loaded += new RoutedEventHandler(Window2_Loaded);
            }
    
            public void palymusic(string msg)
            {
                MessageBox.Show(msg,"---------title-------",MessageBoxButton.OKCancel);
            }
           private void button1_Click(object sender, RoutedEventArgs e)
            {
              web.Document.InvokeScript("eval", new string[] { "alert('test msg from web');  window.external.palymusic(777777)" });
    
            }
    
            void Window2_Loaded(object sender, RoutedEventArgs e)
            {
            }
        }
    
    
    
        [System.Runtime.InteropServices.ComVisible(true)] // 将该类设置为com可访问
        public class OprateBasic
        {
    
            private Window2 instance;
            public OprateBasic(Window2 instance)
            {
                this.instance = instance;
            }
    
            public void palymusic(string msg)
            {
               instance.palymusic(msg);
            }
    
    
        }
    
    
    }
    

      

  • 相关阅读:
    犹太人高成就的秘诀
    EXSI宿主机更换硬盘后虚机启动有问题
    Centos7 系统启动docker报错 inotify add watch failed
    Gluster的搭建和使用
    关于HA(2.102 -2.103 服务器排障)
    Fabric的简介
    关于CPU的一些操作(CPU设置超频)
    docker的安装和技巧
    linux 下查看wwn号
    HP 3par多路径安装方法
  • 原文地址:https://www.cnblogs.com/wgscd/p/9342264.html
Copyright © 2020-2023  润新知