zoukankan      html  css  js  c++  java
  • WPF webbowser 交互

    //

    <Window x:Class="WpfApp1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:winform="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    
    
        xmlns:local="clr-namespace:WpfApp1"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
    
            <wfi:WindowsFormsHost x:Name="c_wfh" Margin="0,90,0,0">
                <winform:WebBrowser ScriptErrorsSuppressed="True"  x:Name="web">
                </winform:WebBrowser>
            </wfi:WindowsFormsHost>
            <Button Content="Button" HorizontalAlignment="Left" Margin="34,10,0,0" VerticalAlignment="Top" Width="120" Height="75" Click="Button_Click"/>
        </Grid>
    </Window>
    

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    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.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApp1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                web.ObjectForScripting = new OprateBasic();
                Loaded += MainWindow_Loaded;
                web.Navigate("https://www.runoob.com/w3cnote/javascript-settimeout-usage.html");
            }
    
            private void MainWindow_Loaded(object sender, RoutedEventArgs e)
            {
                WebbowserHelper.SetWebBrowserFeatures(11);
            }
    
            private void Button_Click(object sender, RoutedEventArgs e)
            {
    
                //  web.Document.InvokeScript("eval", new string[] { "function tt(){ window.external.NotifyMsg(new Date()); } ;setTimeout('tt', 3000);" }); 
                // web.Document.InvokeScript("eval", new string[] { "if(document.getElementsByClassName('fff').length>0){window.external.NotifyMsg(66)} else{window.external.NotifyMsg(0)};" });
                //下面这种也可以返回数据
                var i = web.Document.InvokeScript("eval", new string[] { "if(document.getElementsByClassName('fff').length>0){  1;} else{  0;}" });
                Title = "" + i;
    
            }
    
        }
    
        [System.Runtime.InteropServices.ComVisible(true)]
        public class OprateBasic
        {
            public void NotifyMsg(string msg)
            {
                MessageBox.Show(msg);
            }
        }
    }
    

      

  • 相关阅读:
    H3C 路由策略(人为打环)
    linux nfs配置
    linux vsftp 简单配置
    linux vg lv pv
    linux sshd 登录不需要密码
    linux dhcp 简单配置
    linux pxe 安装Centos7
    分别使用laravel安装器和composer安装laravel!
    阻止按钮快速点击
    检测页面是否允许使用Flash
  • 原文地址:https://www.cnblogs.com/wgscd/p/13476609.html
Copyright © 2011-2022 走看看