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

      

  • 相关阅读:
    Vuex 在state中存取数据 modules分模块 (2018/11/28)
    计数器(2018/11/29)
    03$router和$route的区别 (2018/11/28)
    02导航守卫 (2018/11/28)
    01模拟用户的登录 (2018/11/27)
    路由传参(2018/11/26)
    CSS制作红桃心
    css制作三角形
    css内容超出显示省略号
    css制作旋转风车(transform 篇)
  • 原文地址:https://www.cnblogs.com/wgscd/p/9342264.html
Copyright © 2011-2022 走看看