zoukankan      html  css  js  c++  java
  • webbrowser

    把 WebBrowser 中已经显示的 Html 代码显示出来

    webBrowser1.Document.Body.OuterHtml


    禁用错误脚本提示

    此方法不能屏蔽脚本调试窗口,自己改了关闭Ie的调试

            private SHDocVw.IWebBrowser2 Iwb2;

            protected override void AttachInterfaces(object nativeActiveXObject)
            {
                Iwb2 = (SHDocVw.IWebBrowser2)nativeActiveXObject;
                Iwb2.Silent = true;
                base.AttachInterfaces(nativeActiveXObject);
            }


            protected override void DetachInterfaces()
            {
                Iwb2 = null;
                base.DetachInterfaces();
            }

        //判断是否网络正常 
        private  bool IsConnectedToInternet()
            {

                int Desc;
                return internet.InternetGetConnectedState(out  Desc, 0);
            }  

        //设置默认页面:
        webBrowser1.Navigate(new Uri("http://www.ic2ic.com/copy.jsp"));

        //登录代码:
            private void btnlogin_Click(object sender, EventArgs e)
            {
                webBrowser1.Document.GetElementById("id").InnerText =txtuser.Text.ToString().Trim();//fill name
                webBrowser1.Document.GetElementById("passwd").InnerText =txtpwd.Text.ToString().Trim();//fill pwd
                HtmlElement formLogin = webBrowser1.Document.Forms["frmLogin"];
                formLogin.InvokeMember("submit");
                Thread.Sleep(5000);
                herfclick("http://www.ic2ic.com/upload.jsp");//这是登录成功的操作,跳转到//upload.asp

                                                             //注意不是直接跳过去的,模拟点击链接

                                                             //SESSION不会丢失

                herfclick("http://www.ic2ic.com/copy.jsp");

            }

            //模拟点击链接:

            private void herfclick(string url)
            {

                for (int i = 0; i < webBrowser1.Document.All.Count; i++)
                {

                    if (webBrowser1.Document.All[i].TagName == "A" && webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim() ==url)
                    {

                        webBrowser1.Document.All[i].InvokeMember("click");//引发”CLICK”事件
                        break;
                    }

                }    
            }

         //运行网页中的JS函数

          private  void callJsMethod(string jsfun,string jsParameter)//函数名字,函数参数
          {

                HtmlDocument doc = webBrowser1.Document;
                doc.InvokeScript(jsfun,new object[]...{jsParameter});

            }

         //填充数据:

          private void filldate(string txt)
          {

                HtmlElement frmWord = webBrowser1.Document.Forms["frmWord"];//找到from
                HtmlElementCollection txtarea = frmWord.GetElementsByTagName("TEXTAREA");
                HtmlElementCollection radio = frmWord.GetElementsByTagName("INPUT");
                radio[2].InvokeMember("click");//选择radio控件
                txtarea[0].InnerText = txt.ToString();
          }

          //文档是否加载完成

          private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (e.Url == webBrowser1.Document.Url)
                {}

        }

  • 相关阅读:
    【[SDOI2014]旅行】
    【[USACO16OPEN]262144】
    【[SDOi2012]Longge的问题】
    【[POI2000]病毒】
    【不同子串个数】
    【工艺】
    Lambda使用深入解析
    Lambda表达式语法进一步巩固
    给之前绘制的图形菜单增加随触摸360度旋转效果
    给之前绘制的饼状图增加点击扩大突出效果
  • 原文地址:https://www.cnblogs.com/50614090/p/1908157.html
Copyright © 2011-2022 走看看