日韩欧美人妻无码精品白浆,夜夜嗨AV免费入口,国产欧美官网在线看,高校回应聋哑女生因长相完美被质疑

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

[點(diǎn)晴永久免費(fèi)OA]C# WebBrowser 屏蔽alert,confirm的方法

admin
2022年12月15日 15:51 本文熱度 1539

WebBrowser屏蔽alert是用重定義alert,confirm實(shí)現(xiàn)的。比較簡單。代碼如下:
添加 com 引用 microsoft html object library
using mshtml;

1、頁面一加載就有彈出框的自動點(diǎn)擊(屏蔽)

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow;
string s = @"function confirm() {return true;}";
s += @"function alert() {}";
win.execscript(s, "javascript");
}

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
      {
          //自動點(diǎn)擊彈出確認(rèn)或彈出提示
          IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
          vDocument.parentWindow.execscript("function confirm(str){return true;} ""javascript"); //彈出確認(rèn)
          vDocument.parentWindow.execscript("function alert(str){return true;} ""javascript");//彈出提示
      }


2、WebBrowser頁面加載完畢之后,在頁面中進(jìn)行一些自動化操作的時候彈出框的自動點(diǎn)擊(屏蔽)

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //自動點(diǎn)擊彈出確認(rèn)或彈出提示
            IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            vDocument.parentWindow.execscript("function confirm(str){return true;} ""javascript"); //彈出確認(rèn)
            vDocument.parentWindow.execscript("function alert(str){return true;} ""javascript");//彈出提示
//下面是你的執(zhí)行操作代碼
}


我的不是這樣弄的,雖然代碼一樣,但是我是在執(zhí)行具體任務(wù)的時候,才會寫入這個,然后執(zhí)行這段代碼+我自己的點(diǎn)擊代碼。

剛才在網(wǎng)上找了下,還有另一種治本的方法呵,高人到處都是。下面是代碼,是繼承的webBrowser然后屏弊了ShowMessage

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Test
{

public class MyWebBrowser : System.Windows.Forms.WebBrowser
{
#region ExtendedWebBrowserSite
class ExtendedWebBrowserSite : WebBrowser.WebBrowserSite, UnsafeNativeMethods.IDocHostShowUI
{
public ExtendedWebBrowserSite(WebBrowser host)
: base(host)
{
}


void UnsafeNativeMethods.IDocHostShowUI.ShowMessage(ref UnsafeNativeMethods._RemotableHandle hwnd, string lpstrText, string lpstrCaption, uint dwType, string lpstrHelpFile, uint dwHelpContext, out int plResult)
{
plResult = 0;
//TODO:自定義
}
void UnsafeNativeMethods.IDocHostShowUI.ShowHelp(ref UnsafeNativeMethods._RemotableHandle hwnd, string pszHelpFile, uint uCommand, uint dwData, UnsafeNativeMethods.tagPOINT ptMouse, object pDispatchObjectHit)
{
//TODO:自定義
}
}

protected override WebBrowserSiteBase createWebBrowserSiteBase()
{
return new ExtendedWebBrowserSite(this);
}
#endregion
}

public class UnsafeNativeMethods
{
#region IDocHostShowUI
[StructLayout(LayoutKind.Explicit, Pack = 4)]
public struct __MIDL_IWinTypes_0009
{
// Fields
[FieldOffset(0)]
public int hInproc;
[FieldOffset(0)]
public int hRemote;
}

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct _RemotableHandle
{
public int fContext;
public __MIDL_IWinTypes_0009 u;
}

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct tagPOINT
{
public int x;
public int y;
}

[ComImport, Guid("C4D244B0-D43E-11CF-893B-00AA00BDCE1A"), InterfaceType((short)1)]
public interface IDocHostShowUI
{
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void ShowMessage([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrText, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrCaption, [In] uint dwType, [In, MarshalAs(UnmanagedType.LPWStr)] string lpstrHelpFile, [In] uint dwHelpContext, [ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.LONG_PTR")] out int plResult);
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
void ShowHelp([In, ComAliasName("ExtendedWebBrowser2.UnsafeNativeMethods.wireHWND")] ref _RemotableHandle hwnd, [In, MarshalAs(UnmanagedType.LPWStr)] string pszHelpFile, [In] uint uCommand, [In] uint dwData, [In] tagPOINT ptMouse, [Out, MarshalAs(UnmanagedType.IDispatch)] object pDispatchObjectHit);
}
#endregion

}
}
這個是直接復(fù)制過來的啊,這編輯器沒有代碼功能,汗。。。有點(diǎn)亂。但很好的屏弊webBrowser里的alert,confirm了。

不管怎么樣,有二種方法,可以實(shí)現(xiàn)webBrowser屏弊alert了。


該文章在 2022/12/15 15:51:02 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊、財務(wù)費(fèi)用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved