Webbrowser Method for blocking alert and confirm

Source: Internet
Author: User
Webbrowser shielding alert is implemented by redefinition of alert and confirm. Relatively simple. Code As follows:
Add com reference Microsoft HTML Object Library
Using Mshtml;

Private Void Webbrowser1_navigated ( Object Sender, webbrowsernavigatedeventargs E)
{
Ihtmlwindow2 win = (ihtmlwindow2) webbrowser1.document. Window. domwindow;
String S = @" Function confirm (){ " ;
S + = @" Return true; " ;
S + = @" } " ;
S + = @" Function alert (){} " ;
Win.exe cscript (S, " Javascript " );
}

(Provided by computer repair networkProgramSupported)

This is not what I did. Although the Code is the same, I write the code only when executing a specific task, and then execute this code + my own click code.

I found it on the Internet just now. There is another way to cure the problem. High people are everywhere. Below is the code, which is the inherited webbrowser and then the screen cheating 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: custom
}
Void Unsafenativemethods. idochostshowui. showHelp ( Ref Unsafenativemethods. _ remotablehandle hwnd, String Pszhelpfile, Uint Ucommand, Uint Dwdata, unsafenativemethods. tagpoint ptmouse, Object Pdispatchobjecthit)
{
// Todo: custom
}
}

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, exploralas (unmanagedtype. lpwstr)] String Lpstrtext, [in, financialas (unmanagedtype. lpwstr)] String Lpstrcaption, [in] Uint Dwtype, [in, financialas (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, exploralas (unmanagedtype. lpwstr)] String Pszhelpfile, [in] Uint Ucommand, [in] Uint Dwdata, [in] tagpoint ptmouse, [out, financialas (unmanagedtype. idispatch)] Object Pdispatchobjecthit );
}
# Endregion

}
}
This is copied directly. This editor does not have the code function, Khan... A little messy. But the screen cheating webbrowser's alert and confirm is good.

Either way, you can implement webbrowser screen cheating alert.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.