Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
            element.text = "function sayHello() { var objs = new Array(4);  alert(__HOST__.img_prefix); var b = arr_pages.join(\"|\"); return b; }";//var b = objs.join(\"-\");
            //IHTMLScriptElement el;

            head.AppendChild(scriptEl);
            ////webBrowser1.Document.InvokeScript("sayHello");
            ////string jCode = "alert(\"HelloHelloHelloHello\");";
            //// or any combination of your JavaScript commands
            //// (including function calls, variables... etc)
            //IHTMLDocument2 aa;
            //// WebBrowser webBrowser1 is what you are using for your web browser
            ////webBrowser1.Document.InvokeScript("eval", new object[] { jCode });
            //object[] objs = new object[4];
            //object obj = webBrowser1.Document.InvokeScript("jsAlert", new String[] { "info1", "info2" });
            //MessageBox.Show(objs.ToString());
            IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
            IHTMLWindow2 vWindow = vDocument.parentWindow;
            Type vWindowType = vWindow.GetType();
            ArrayList alist = new ArrayList();
            string[] strs = new string[4];
            //object xpt = vWindowType.InvokeMember("_xpt", BindingFlags.GetProperty, null, vWindow, new object[] { });

            object getarr =  webBrowser1.Document.InvokeScript("sayHello", new object[] { });
            MessageBox.Show(getarr.ToString());
        }
Exemplo n.º 2
0
        public void ShowData(string funName, object[] paras)
        {
            IHTMLWindow2 htmlWin = owin as IHTMLWindow2;

            //以下是调用方法,由于仅仅是示例,所以直接放在SetFunc方法中了。实际开发中,大家根据情况放到相应地方。
            //这里调用的方法我提供了两种:1,反射的方法;2,JS代码语法。
            //大家可以根据自己熟悉的情况采用适合自己的方法。两种方法的效果都是一样的。
            //方法1。
            htmlWin.GetType().InvokeMember(funName,
                                           BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,
                                           null, htmlWin, paras);
        }
Exemplo n.º 3
0
        private static object InvokeMember(IHTMLWindow2 window, string function, string arguments)
        {
            try
            {
                return(window.GetType().InvokeMember(function, BindingFlags.InvokeMethod, null, window, new object[] { arguments }));
            }
            catch (Exception)
            {
                // ignored - we can't run js on some frames - like google ads etcs
            }

            return(null);
        }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                IHTMLDocument2 d2 = this.mainWebBrowser.Document.DomDocument as IHTMLDocument2;
                IHTMLWindow2   w2 = (IHTMLWindow2)d2.parentWindow;

                Type   windowType = w2.GetType();
                String testText   = (String)windowType.InvokeMember("testparam",
                                                                    System.Reflection.BindingFlags.GetProperty, null, w2, new Object[] { });
                mainForm.targetAttribute = testText;

                MessageBox.Show(mainForm.targetAttribute);
            }
            catch
            {
            }
        }
Exemplo n.º 5
0
        public void ShowData(string Name, string Gender, string Folk,
                             string BirthDay, string Code, string Address,
                             string Agency, string ExpireStart, string ExpireEnd, string ImageBase64String)
        {
            IHTMLWindow2 htmlWin = owin as IHTMLWindow2;

            //以下是调用方法,由于仅仅是示例,所以直接放在SetFunc方法中了。实际开发中,大家根据情况放到相应地方。
            //这里调用的方法我提供了两种:1,反射的方法;2,JS代码语法。
            //大家可以根据自己熟悉的情况采用适合自己的方法。两种方法的效果都是一样的。
            //方法1。
            htmlWin.GetType().InvokeMember(funcName,
                                           BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,
                                           null, htmlWin, new object[] { Name, Gender, Folk,
                                                                         BirthDay, Code, Address,
                                                                         Agency, ExpireStart, ExpireEnd, ImageBase64String });

            //方法2。
            //string jsCode = string.Format("{0}('{1}')", funcName, "参数");
            //htmlWin.execScript(jsCode, "jscript");

            //CallJavaScript("GetData(\"" + Name + "\",\"" + Gender + "\",\"" + Folk + "\",\"" + BirthDay + "\",\"" + Code + "\",\"" + Address + "\",\"" + Agency + "\",\"" + ExpireStart + "\",\"" + ExpireEnd + "\",\"" + ImageBase64String + "\")");
        }
Exemplo n.º 6
0
        void vote(List <AgentIPModel> ipList)
        {
            foreach (AgentIPModel ipm in ipList)
            {
                //是否需要检验?

                //投票
                newip = string.Format("{0}:{1}", ipm.ip, ipm.port);
                promaxy1.IEProxy.SetProxy(newip);
                webBrowserOK = false;
                webBrowser1.Navigate(newip);

                for (int i = 10; i > 0; i--)
                {
                    Thread.Sleep(800);
                    if (webBrowserOK)
                    {
                        break;
                    }
                }
                if (webBrowserOK)
                {
                    addClick();
                    Thread.Sleep(1000);

                    if (webBrowser1.InvokeRequired)
                    {
                        webBrowser1.Invoke(new Action(() =>
                        {
                            IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
                            IHTMLWindow2 vWindow     = (IHTMLWindow2)vDocument.parentWindow;
                            Type vWindowType         = vWindow.GetType();
                            object testText          = vWindowType.InvokeMember("g_msg", BindingFlags.GetProperty, null, vWindow, new object[] { });
                            if (testText + "" == "1")
                            {
                                //成功
                                totalSetCount++;
                                total1Count++;
                                ipm.LastSuccess = true;
                            }
                            else if (testText + "" == "0")
                            {
                                total0Count++;
                            }
                            else if (testText + "" == "")
                            {
                                totalEmptyCount++;
                            }
                            else
                            {
                                totalOther++;
                            }
                        }));
                    }

                    ipm.LastCheckData = DateTime.Now;
                    ipBLL.Update(ipm);
                    Thread.Sleep(2000);
                }
                Thread.Sleep(100);
            }
        }