zoukankan      html  css  js  c++  java
  • 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);
            }
    
    
        }
    
    
    }
    

      

  • 相关阅读:
    vue学习之router
    vue学习之组件
    xshell操作
    Webstorm快捷操作
    javascript判断节点是否在dom
    影子节点 shadowDOM
    虚拟节点操作——DocumentFragment
    理解浏览器的历史记录
    浏览器渲染
    web请求流程
  • 原文地址:https://www.cnblogs.com/wgscd/p/9342264.html
Copyright © 2011-2022 走看看