WPF WebBrowser Control-critical code

Source: Internet
Author: User

1. Gets the value of the element, based on the element ID.

For example to get This the value of the SRC attribute in the tag:

Mshtml. IHTMLDocument2 doc2 = (mshtml. IHTMLDocument2) webbrowser1.document; Mshtml. IHTMLElement img = (mshtml. IHTMLElement) Doc2.all.item ("Regimg", 0);

String imgurl = (string) img.getattribute ("src");

2. Fill out the form and determine

Mshtml. IHTMLElement LoginName = (mshtml.     IHTMLElement) Doc2.all.item ("LoginName", 0); Mshtml. IHTMLElement LOGINPW = (mshtml.     IHTMLElement) Doc2.all.item ("password", 0); Mshtml. IHTMLElement LOGINBT = (mshtml.     IHTMLElement) Doc2.all.item ("Formsubmit", 0); Mshtml. IHTMLElement Loginyz = (mshtml.     IHTMLElement) Doc2.all.item ("Regcode", 0); Loginname.setattribute ("value", tbloginname.text);
Loginpw.setattribute ("value", Tbloginpassword.password);
Loginyz.setattribute ("value", tbyz.text);
Loginbt.click ();

3. Get the source code

TextBox1.Text = Doc2.body.innerHTML;

4. Execute JS

Mshtml. IHTMLWindow2 win = (mshtml. IHTMLWINDOW2) Doc2.parentwindow;
Win.execscript ("changeregimg ()", "JavaScript");//Use JS

5, prohibit JS,WPF under the current discovery only applicable one method:

public void Hidescripterrors (WebBrowser WB, BOOL Hide)
{
FieldInfo Ficomwebbrowser = typeof (WebBrowser). GetField ("_axiwebbrowser2", BindingFlags.Instance | BindingFlags.NonPublic);

if (Ficomwebbrowser = = null) return;

Object objcomwebbrowser = Ficomwebbrowser.getvalue (WB);

if (Objcomwebbrowser = = null) return;

Objcomwebbrowser.gettype (). InvokeMember ("Silent", BindingFlags.SetProperty, Null,objcomwebbrowser, new object[] {Hide});

}

void Webbrowser1_navigated (object sender, NavigationEventArgs e)
{

Hidescripterrors (WebBrowser1, true);

}

WPF WebBrowser Control-critical code

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.