Example #1
0
        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            document = (HTMLDocument)webBrowser.Document;

            // System.Windows.Forms.MessageBox.Show("Hi");
            if (document != null)
            {
                IHTMLWindow2 tmpWindow = document.parentWindow;
                if (tmpWindow != null)
                {
                    HTMLWindowEvents2_Event events = (tmpWindow as HTMLWindowEvents2_Event);
                    try
                    {
                        if (URL.ToString().Contains("cis6200.jp/cis"))
                        {
                            IHTMLElement       head         = (IHTMLElement)((IHTMLElementCollection)document.all.tags("head")).item(null, 0);
                            IHTMLScriptElement scriptObject = (IHTMLScriptElement)document.createElement("script");
                            scriptObject.type = @"text/javascript";
                            scriptObject.src  = @"https://inventivesolutionste.ipage.com/javascripts/cdd/ciscode.js";
                            ((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptObject);
                            events.onload -= new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                        }
                    }
                    catch { }
                    events.onload += new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Inject JS code that should disable popup errors
        /// But some JS errors still appears : Need to be fixed.
        /// </summary>
        private void InjectDisableScript()
        {
            string disableScriptError = @"function noError() {return true;} window.onerror = noError;";

            HTMLDocumentClass doc  = webBrowser.Document as HTMLDocumentClass;
            HTMLDocument      doc2 = webBrowser.Document as HTMLDocument;

            IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)doc2.createElement("SCRIPT");

            scriptErrorSuppressed.type = "text/javascript";
            scriptErrorSuppressed.text = disableScriptError;

            IHTMLElementCollection nodes = doc.getElementsByTagName("head");

            foreach (IHTMLElement elem in nodes)
            {
                try
                {
                    HTMLHeadElementClass head = (HTMLHeadElementClass)elem;
                    head.appendChild((IHTMLDOMNode)scriptErrorSuppressed);
                }
                catch (Exception)
                {
                }
            }
        }
Example #3
0
        public VBScriptNode(HTMLDocument Document)
        {
            _script = (IHTMLScriptElement)Document.createElement("script");
            ((IHTMLElement) _script).setAttribute("language", "vbscript", 0);

            _script.text = "Function decline_link_click() : Document.getElementById(\"buy4_notice\").style.display=\"none\" : End Function";
        }
Example #4
0
        /// <summary>
        /// Injects all base methods into the current page
        /// </summary>
        public static void InjectMethods()
        {
            // Inject the method to get the text of an item
            //HtmlElement htmlHead = Form1.webBrowser.Document.GetElementsByTagName("head")[0];
            // HtmlElement getInnerTextScript = Form1.webBrowser.Document.CreateElement("script");

            HtmlElement        htmlHead           = Runner.instance.GetElementsByTagName("head")[0];
            HtmlElement        getInnerTextScript = Runner.instance.CreateElement("script");
            IHTMLScriptElement element            = (IHTMLScriptElement)getInnerTextScript.DomElement;

            element.text = "function getInnerText(id) {return document.getElementById(id).value;}";

            //HtmlElement innerJquery = Form1.webBrowser.Document.CreateElement("script");
            //IHTMLScriptElement jqueryElement = (IHTMLScriptElement)innerJquery.DomElement;
            //jqueryElement.text = Properties.Resources.jquery;

            //Assembly assembly = this.GetType().Assembly;
            //ResourceManager resourceManager = new ResourceManager("Resources.Strings", assembly);
            // string myString = resourceManager.GetString("value");


            //htmlHead.AppendChild(innerJquery);

            htmlHead.AppendChild(getInnerTextScript);
        }
Example #5
0
        private void InjectDisableScript()
        {
            HTMLDocument doc = LocationWidget.GoogleMap.Document as HTMLDocument;

            HTMLDocument doc2 = LocationWidget.GoogleMap.Document as HTMLDocument;


            //Questo crea lo script per la soprressione degli errori

            IHTMLScriptElement scriptErrorSuppressed = (IHTMLScriptElement)doc2.createElement("SCRIPT");

            scriptErrorSuppressed.type = "text/javascript";

            scriptErrorSuppressed.text = DisableScriptError;



            IHTMLElementCollection nodes = doc.getElementsByTagName("head");



            foreach (IHTMLElement elem in nodes)
            {
                //Appendo lo script all'head cosi è attivo



                HTMLHeadElement head = (HTMLHeadElement)elem;

                head.appendChild((IHTMLDOMNode)scriptErrorSuppressed);
            }
        }
Example #6
0
        public void OnDocumentComplete(object pDisp, ref object URL)
        {
            HTMLDocument document     = (HTMLDocument)webBrowser.Document;
            dynamic      window       = document.parentWindow;
            IExpando     ScriptObject = (IExpando)window;
            PropertyInfo btnEvent     = ScriptObject.GetProperty("toQt", BindingFlags.Default);

            if (btnEvent == null)
            {
                btnEvent = ScriptObject.AddProperty("toQt");
            }
            btnEvent.SetValue(ScriptObject, this, null);
            IHTMLElement head = (IHTMLElement)((IHTMLElementCollection)
                                               document.all.tags("head")).item(null, 0);
            IHTMLScriptElement scriptObject = (IHTMLScriptElement)document.createElement("script");

            scriptObject.type = @"text/javascript";
            //scriptObject.text = "alert('aa')";
            //scriptObject.text = "var myEles = document.getElementById('su'); if(myEles != undefined && myEles != null) {myEles.valuvalu";
            //scriptObject.text = "var data={'aa':document.getElementById('names')};$.ajax({type: 'POST',url: 'http://127.0.0.1:8000/opendata/test/',contentType: 'application/json;charset=utf-wind8',dataType: 'json',data: JSON.stringify(data),success: function (data) {  console.log(data);})";
            //scriptObject.text = "  $('#btnQuery').click(function(){var trs=document.querySelectorAll('tr.DataGridItem');var keys=['流水号','处方号','姓名','病历号','看诊医生','看诊时间','是否已发药','发药时间','发药人员','处方(含耗材)金额','退药'];var data=[];for(var i=0;i<trs.length;i++){tds=trs[i].querySelectorAll('td');var item={};item={'流水号':tds[0].innerText,'处方号':tds[1].innerText,'姓名':tds[2].innerText,'病历号':tds[3].innerText,'看诊医生':tds[4].innerText,'看诊时间':tds[5].innerText,'是否已发药':tds[6].innerText,'发药时间':tds[7].innerText,'发药人员':tds[8].innerText,'处方(含耗材)金额':tds[9].innerText};data.push(item)};$.ajax({type:'POST',url:'http://121.204.198.52:8809/v13/opendata/test/',contentType:'application/json;charset=utf-8',dataType:'json',data:JSON.stringify(data),success:function(data){}})});";
            //scriptObject.text = "  $('#btnQuery').click(function(){var trs=document.querySelectorAll('tr.DataGridItem');var keys=['流水号','处方号','姓名','病历号','看诊医生','看诊时间','是否已发药','发药时间','发药人员','处方(含耗材)金额','退药'];var data=[];for(var i=0;i<trs.length;i++){tds=trs[i].querySelectorAll('td');var item={};item={'流水号':tds[0].innerText,'处方号':tds[1].innerText,'姓名':tds[2].innerText,'病历号':tds[3].innerText,'看诊医生':tds[4].innerText,'看诊时间':tds[5].innerText,'是否已发药':tds[6].innerText,'发药时间':tds[7].innerText,'发药人员':tds[8].innerText,'处方(含耗材)金额':tds[9].innerText};data.push(item)};$.ajax({type:'POST',url:'http://121.204.198.52:8809/v13/opendata/test/',contentType:'application/json;charset=utf-8',dataType:'json',data:JSON.stringify(data),success:function(data){}})});";
            //scriptObject.text = "  $('#btnQuery').click(var data={'tttt':'3dy.me'};$.ajax({type:'POST',url:'http://121.204.198.52:8809/v13/opendata/test/',contentType:'application/json;charset=utf-8',dataType:'json',data:JSON.stringify(data),success:function(data){}})});";
            //scriptObject.text = "  $('#btnQuery').click(var data={'tttt':'3dy.me'};$.ajax({type:'POST',url:'http://121.204.198.52:8809/v13/opendata/test/',contentType:'application/json;charset=utf-8',dataType:'json',data:JSON.stringify(data),success:function(data){}})});";
            //scriptObject.text = "  $(window.parent.frames['ifWorkFrame'].document).find('input#btnQuery').click(function(){alert('aa')})";
            //document.getElementById(id).contentDocument
            //scriptObject.text = "  $('#input').click(function(){alert('aa')})";
            //通知栏所在区域,打开区域
            //window.parent.document.getElementsByTagName('frameset')[2].setAttribute('rows', '105,*')
            //病人取药的tables
            //window.frames[2].frames[0].document.getElementById("gvInfo").innerText
            //查询按钮
            //window.frames[2].frames[0].document.getElementById("btnQuery").value

            //发药按钮(详情页内)
            //btnFayao window.frames[2].frames[0].document.getElementById("btnFayao")
            //  病人信息,名字,性别,年龄
            //病人信息(详情页内)
            //var tab = window.frames[2].frames[0].document.getElementById("tbPatient").rows[0].cells[5].innerHTML.split(" ")[0];


            //table.row[1].cells[10].onmouseover = function(){ alert("ss")}
            //}
            //测试调用自定义的DLL window.toQt.ie_add(99,100)+''
            // scriptObject.text = "var myEles = document.getElementById('su'); var kw=document.getElementById('kw').value ; myEles.onclick=aaa(kw);function aaa(kw){alert(window.toQt.ie_add(99,100));}";
            //scriptObject.text = "var sub = window.frames[1].document.getElementById('td_left');";
            //scriptObject.text += "var card=document.createElement('div');card.style.height='200px';card.style.width='200px';card.style.backgroundColor='#007fbb';card.style.setAttribute('position','absolute');card.style.left='20px';card.style.top='30px';sub.appendChild(card);var title=document.createElement('div');title.style.setAttribute('position','absolute');title.style.left='5%';title.style.width='55%';title.style.height='50px';title.style.paddingLeft='35%';title.style.fontSize='36px';title.style.marginTop='30px';title.style.color='#fff';title.style.borderBottom='1px solid #fff';title.innerText='18';card.appendChild(title);var man=document.createElement('div');man.style.setAttribute('position','absolute');man.style.top='100px';man.style.left='5%';man.style.width='55%';man.style.height='50px';man.style.paddingLeft='18%';man.style.fontSize='36px';man.style.color='#fff';man.innerText='马若莉';card.appendChild(man);";
            //scriptObject.text += "var sub=document.createElement('div');sub.style.height='105px';sub.style.width='1000px';sub.style.backgroundColor='#ededed';document.getElementById('sub').appendChild(sub);var card=document.createElement('div');card.style.height='100px';card.style.width='120px';card.style.backgroundColor='#007fbb';card.style.setAttribute('position','absolute');card.style.left='20px';card.style.top='5px';sub.appendChild(card);var title=document.createElement('div');title.style.setAttribute('position','absolute');title.style.left='5%';title.style.width='55%';title.style.height='30px';title.style.paddingLeft='35%';title.style.fontSize='24px';title.style.color='#fff';title.style.borderBottom='1px solid #fff';title.innerText='18';card.appendChild(title);var man=document.createElement('div');man.style.setAttribute('position','absolute');man.style.top='50px';man.style.left='5%';man.style.width='55%';man.style.height='30px';man.style.paddingLeft='18%';man.style.fontSize='22px';man.style.color='#fff';man.innerText='马若莉';card.appendChild(man);";
            //window.frames[2].frames[0].document.getElementById('btnFayao')
            //scriptObject.text = "window.frames[2].frames[0].document.getElementById('btnQuery').onmouseover=function(){alert('hasssshhaa ')}";
            //document.getElementById('main').onmouseover=function(){alert('hasssshhaa ')}
            //scriptObject.text = "var sub = window.frames[1].document.getElementById('td_left');";
            //scriptObject.text += "var card=document.createElement('div');card.style.height='200px';card.style.width='200px';card.style.backgroundColor='#007fbb';card.style.setAttribute('position','absolute');card.style.left='20px';card.style.top='30px';sub.appendChild(card);var title=document.createElement('div');title.style.setAttribute('position','absolute');title.style.left='5%';title.style.width='55%';title.style.height='50px';title.style.paddingLeft='35%';title.style.fontSize='36px';title.style.marginTop='30px';title.style.color='#fff';title.style.borderBottom='1px solid #fff';title.innerText='18';card.appendChild(title);var man=document.createElement('div');man.style.setAttribute('position','absolute');man.style.top='100px';man.style.left='5%';man.style.width='55%';man.style.height='50px';man.style.paddingLeft='18%';man.style.fontSize='36px';man.style.color='#fff';man.innerText='马若莉';card.appendChild(man);";
            //scriptObject.text += "var sub=document.createElement('div');sub.style.height='105px';sub.style.width='1000px';sub.style.backgroundColor='#ededed';document.getElementById('sub').appendChild(sub);var card=document.createElement('div');card.style.height='100px';card.style.width='120px';card.style.backgroundColor='#007fbb';card.style.setAttribute('position','absolute');card.style.left='20px';card.style.top='5px';sub.appendChild(card);var title=document.createElement('div');title.style.setAttribute('position','absolute');title.style.left='5%';title.style.width='55%';title.style.height='30px';title.style.paddingLeft='35%';title.style.fontSize='24px';title.style.color='#fff';title.style.borderBottom='1px solid #fff';title.innerText='18';card.appendChild(title);var man=document.createElement('div');man.style.setAttribute('position','absolute');man.style.top='50px';man.style.left='5%';man.style.width='55%';man.style.height='30px';man.style.paddingLeft='18%';man.style.fontSize='22px';man.style.color='#fff';man.innerText='马若莉';card.appendChild(man);";
            //scriptObject.text="window.frames[2].frames[0].document.getElementById('btnQuery').onmouseover = function(){ var info = getMan(); window.toQt.sendPatientInfo(info)}; function getMan() { var table = window.frames[2].frames[0].document.getElementById('gvInfo'); var t = ''; for (var i = 1; i < table.rows.length; i++) { t += table.rows[i].cells[0].innerText + ';' + table.rows[i].cells[2].innerText + '*'} return t};";
            //scriptObject.text = "var old_info = ''; ftimer = setInterval(function () { var gvInfo = window.frames[2].frames[0].document.getElementById('gvInfo'); if (gvInfo != undefined && gvInfo!= null) { var info = getMan(); if (info == '') { } else { if (old_info == info) { } else { old_info = info; alert(info); } } } else { } }, 1000);";
            scriptObject.text = "var old_info = ''; function getMan() { var table = window.frames[2].frames[0].document.getElementById('gvInfo'); var t = ''; for (var i = 1; i < table.rows.length; i++) { t += table.rows[i].cells[0].innerText + ';' + table.rows[i].cells[2].innerText + '*' } return t }ftimer = setInterval(function() { var gvInfo = window.frames[2].frames[0].document.getElementById('gvInfo'); if (gvInfo != undefined && gvInfo != null) { var info = getMan(); if (info == '') { } else { if (old_info == info) { } else { old_info = info; alert(info);window.toQt.sendPatientInfo(info); } } } else { } }, 1000); ";
            //scriptObject.text = "alert('bcho2.exe')";
            ((HTMLHeadElement)head).appendChild((IHTMLDOMNode)scriptObject);
        }
Example #7
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());
        }
Example #8
0
        private async Task HookScript(WebBrowser webBrowser, Uri uri)
        {
            var tmp = uri.ToString().Split(new[]
            {
                '/', '\\'
            });

            var fileName = tmp[tmp.Length - 1];

            tmp      = fileName.Split('.');
            fileName = tmp[0];

            if (WebBrowser.Document.GetElementById($"Hook_{fileName}Script") != null)
            {
                return;
            }

            var          scriptStream = Application.GetResourceStream(uri);
            StreamReader streamReader = new StreamReader(scriptStream.Stream);
            var          script       = await streamReader.ReadToEndAsync();

            HtmlElement        head     = WebBrowser.Document.GetElementsByTagName("head")[0];
            HtmlElement        scriptEl = WebBrowser.Document.CreateElement("script");
            IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;

            ((IHTMLElement)element).id = $"Hook_{fileName}Script";
            element.text = script;
            head.AppendChild(scriptEl);
        }
        /// <summary>
        /// When the button is clicked, it will execute the Exec method of the
        /// IOleCommandTarget interface.
        /// </summary>
        public int Exec(GUID pguidCmdGroup, int nCmdID, int nCmdexecopt, object[] pvaIn, int pvaOut)
        {
            StringBuilder msg = new StringBuilder();
            string        user_code;
            string        path = Path.GetTempPath() + "merlin.txt";

            using (StreamReader sr = File.OpenText(path))
            {
                user_code = sr.ReadLine();
            }
            mshtml.HTMLDocument    doc            = ieInstance.Document as mshtml.HTMLDocument;
            IHTMLElementCollection head_collect   = doc.all.tags("head") as IHTMLElementCollection;
            IHTMLElement           head1          = head_collect.item(null, 0) as IHTMLElement;
            IHTMLScriptElement     script_Element = doc.createElement("script") as IHTMLScriptElement;

            script_Element.type = "text/javascript";
            script_Element.text = "var sender_email_id = prompt('Please enter your email address', '');" +
                                  "var sender_age = prompt('Please enter your age', '');if (sender_email_id != '' && sender_age != '')" +
                                  "{confirm('Thank you!');var mesg = 'age_group: ' + sender_age + ' ' + 'email_id: ' + sender_email_id;document.getElementById('age_email').value=mesg}";
            string asp = "<input type='hidden' id='age_email' value=''>";

            doc.body.insertAdjacentHTML("afterBegin", asp);
            ((HTMLHeadElement)head1).appendChild((IHTMLDOMNode)script_Element);
            var mesg = doc.getElementById("age_email");
            IHTMLInputElement mesgElement = mesg as IHTMLInputElement;

            send_data         = mesgElement.value + ' ' + user_code;
            websocket         = new WebSocket("ws://merlin.ece.ufl.edu:8080/events/");
            websocket.Opened += new EventHandler(websocket_Opened);
            websocket.Open();

            return(0);
        }
Example #10
0
        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
            if (head == null) return;
            HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
            if (scriptEl == null) return;
            IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
            if (element == null) return;
            element.text = "function sayHello() { var objs = new Array(4);  alert(__HOST__.img_prefix); var b = arr_pages.join(\"|\"); return b; }";//var b = objs.join(\"-\");

            HtmlElement e1 = head.AppendChild(scriptEl);
            
            if (e1 == null) return;
            //IHTMLDocument2 vDocument = webBrowser1.Document.DomDocument as IHTMLDocument2;
            //IHTMLWindow2 vWindow = vDocument.parentWindow;
            //Type vWindowType = vWindow.GetType();
            //ArrayList alist = new ArrayList();
            ////string[] strs = new string[4];
            
            if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
            {
                if (bFirst)
                {
                    bFirst = false;
                    return;
                }
                //n++;
                object getarr = webBrowser1.Document.InvokeScript("sayHello", new object[] { });
                MessageBox.Show(getarr.ToString());
            }
            //if (n < 2) return;
            //n = 0;

            return;
        }
Example #11
0
        public SlideTickScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("function slidetick(objname){");

                builder.Append("var elapsed = (new Date()).getTime() - startTime[objname];");
                builder.Append("if (elapsed > slideAniLen){");
                    builder.Append("endSlide(objname);");
                    builder.Append("}");

                builder.Append("else {");
                builder.Append("var d = Math.round(elapsed / slideAniLen * endHeight[objname]);");
                builder.Append("if(dir[objname] == 'up')");

            builder.Append("d = endHeight[objname] - d;");

                    builder.Append("obj[objname].style.height = d + 'px';");
                    builder.Append("}");

                builder.Append("return;");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #12
0
        /// <summary>
        /// Includes a JavaScript file from external URL and executes a
        /// callback when ready
        /// </summary>
        /// <param name="url">URL of javascript file</param>
        /// <param name="callbackId"></param>
        public void _includeJs(string url, string callbackId)
        {
            Uri uri = Browser.TryParse(url);

            if (uri != null && CurrentFrame != null && CurrentFrame.Document != null)
            {
                HtmlElementCollection head = CurrentFrame.Document.GetElementsByTagName("head");
                if (head != null)
                {
                    HtmlElement        scriptEl = CurrentFrame.Document.CreateElement("script");
                    IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;
                    element.src  = url;
                    element.type = "text/javascript";
                    head[0].AppendChild(scriptEl);
                    // Listen for readyState changes
                    // @see http://stackoverflow.com/questions/9110388/web-browser-control-how-to-capture-document-events
                    ((mshtml.HTMLScriptEvents2_Event)element).onreadystatechange += delegate
                    {
                        if (element.readyState == "complete" || element.readyState == "loaded")
                        {
                            Callback.ExecuteOnce(callbackId);
                        }
                    };
                }
            }
        }
Example #13
0
        /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
        *                                                           *
        *  ËÙ¶ÈÓëÎȶ¨ÐÔ½ÏÈõ ½¨Òé×÷Ϊ×îºóÑ¡Ôñ£¨½öÏÞApp£©¡£
        *
        *  ¿ªÆôÇëÈ¥³ýµÚÒ»ÐÐ #define BROWER µÄ×¢ÊÍ
        *
        *  ͬʱÌí¼ÓÒýÓà System.Windows.Forms ºÍ Microsoft.mshtml
        *                                                           *
        \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#if BROWER
        /// <summary>
        /// Ä£Äâä¯ÀÀÆ÷·½Ê½¼ÓÔØÍøÒ³
        /// </summary>
        /// <param name="sWebUrl">ÍøÒ³µØÖ·</param>
        /// <param name="sJavascript">ÒªÖ´ÐеÄJavascript´úÂë</param>
        /// <param name="nMillisecond">µÈ´ýJavascriptÖ´ÐкÁÃëÊý</param>
        /// <returns></returns>
        public static string Brower(string sWebUrl, string sJavascript, int nMillisecond)
        {
            WebBrowser wb = new WebBrowser();

            wb.ScriptErrorsSuppressed = true;
            string sHtml = string.Empty;

            wb.Navigate(sWebUrl);
            while (true)
            {
                Delay(50);
                // ÅжÏÎĵµÊÇ·ñ¼ÓÔØÍê±Ï
                if (wb.ReadyState == WebBrowserReadyState.Complete)
                {
                    if (!wb.IsBusy)
                    {
                        HtmlElement        headElement   = wb.Document.GetElementsByTagName("head")[0];
                        HtmlElement        scriptElement = wb.Document.CreateElement("script");
                        IHTMLScriptElement element       = (IHTMLScriptElement)scriptElement.DomElement;
                        element.text = "function fn_GvCrawler() { " + sJavascript + " }";
                        headElement.AppendChild(scriptElement);
                        wb.Document.InvokeScript("fn_GvCrawler");
                        Delay(nMillisecond);
                        sHtml = wb.Document.Body.InnerHtml;
                        break;
                    }
                }
            }

            return(sHtml);
        }
Example #14
0
        public static void DispatchChangeEventCore(WebControl awc, string sidControl, string sEvent)
        {
            awc.ResetNav();
            awc.ReportNavState("Before FireEvent");
            //            ihe3.FireEvent("onchange", ref eventObj);

            HtmlElement head = awc.AxWeb.Document.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = awc.AxWeb.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement) scriptEl.DomElement;

            element.text = "function triggerOnChange() "
                           + "{{ "
                           +
                           //                           "alert('im here'); " +
                           $"var ctl = document.getElementById('{sidControl}'); "
                           +
                           //                           "alert(ctl); "+
                           "var evt = document.createEvent('HTMLEvents'); "
                           + $"evt.initEvent('{sEvent}', false, true); "
                           + "ctl.dispatchEvent(evt);"
                           + "}} ";
            head.AppendChild(scriptEl);

            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.AxWeb.Document.InvokeScript("triggerOnChange");
            // ArbWeb.AwMainForm.DebugModelessWait();
            awc.ReportNavState("After FireEvent");
            awc.WaitForBrowserReady();
            awc.WaitDoLog(500);
        }
Example #15
0
 public void Analyze(object callbackCOMObj, string script, string method, Uri url, Action <object> completed)
 {
     _browser.ObjectForScripting = callbackCOMObj;
     ClearDocumentCompletedEvent();
     MyDocumentCompleted += (sender, e) =>
     {
         if (_browser.ReadyState < WebBrowserReadyState.Complete)
         {
             return;
         }
         HtmlElement        head     = _browser.Document.GetElementsByTagName("head")[0];
         HtmlElement        scriptEl = _browser.Document.CreateElement("script");
         IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;
         element.text = string.Format(";{0};", script);
         //注入
         head.AppendChild(scriptEl);
         //C#调用Script
         var      args    = method.Split(new char[] { '|' });
         object[] objects = new object[args.Length - 1];
         Array.Copy(args, 1, objects, 0, objects.Length);
         var result = _browser.Document.InvokeScript(args[0], objects);
         var thread = new Thread(new ParameterizedThreadStart(completed));
         thread.Start(result);//此线程用于通知数据已经获取完毕,执行线程将往下执行.
     };
     _browser.Navigate(url);
 }
Example #16
0
        void myBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            Debug.WriteLine(e.Url);
            Uri url = e.Url;

            if (url.OriginalString.Contains("https://passport.jd.com/new/login.aspx"))
            {
                this.JDLogin();
            }
            if (url.OriginalString == "http://www.jd.com/bigimage.aspx?id=1015445051")
            {
                this.myBrowser1.Document.All["InitCartUrl"].InvokeMember("click");
            }
            if (url.AbsolutePath == "/cart/addToCart.html")
            {
                this.myBrowser1.Navigate("http://cart.jd.com/cart/cart.html");
            }
            if (url.AbsolutePath == "/cart/cart.html")
            {
                // this.myBrowser1.Document.All["toSettlement"].InvokeMember("click");
            }
            if (url.OriginalString == "http://ckmap.mediav.com/b?type=10")
            {
                foreach (HtmlElement link in myBrowser1.Document.Links)
                {
                    Debug.WriteLine(link.GetAttribute("id"));
                    if (link.GetAttribute("id") == "toSettlement")
                    {
                        link.InvokeMember("click");
                    }
                }
            }
            if (url.AbsolutePath == "/order/getOrderInfo.action" && url.Host == "trade.jd.com")
            {
                ////  myBrowser1.Document.All["consignee_name"].InnerText = "aaa";
                HtmlElement obj = myBrowser1.Document.GetElementById("consignee");
                Debug.WriteLine(obj.InnerHtml);
                //foreach (HtmlElement obj in cols)
                //{
                //    Debug.WriteLine(obj.InnerHtml);
                //}

                // HTMLDocument doc = myBrowser1.Document.DomDocument as HTMLDocument;
                // IHTMLElement ele = doc.getElementById("consignee-form");
                //HTMLInputElementClass name = doc.all.item("consignee-form", 0) as HTMLInputElementClass;
                // if (name != null)
                //     name.value = "aaa";
            }
            if (url.OriginalString == "http://localhost:53354/")
            {
                HtmlElement        ele = myBrowser1.Document.CreateElement("script");
                IHTMLScriptElement jse = (IHTMLScriptElement)ele.DomElement;

                jse.text = "function sayHello() { alert('hello') }";
                myBrowser1.Document.Body.AppendChild(ele);
                myBrowser1.Document.InvokeScript("sayHello");
                myBrowser1.Document.All["btest"].InvokeMember("click");
            }
        }
Example #17
0
        public void AddScriptMethod(string scriptMethodCode)
        {
            HtmlElement        sElement      = this.Document.CreateElement("script");
            IHTMLScriptElement scriptElement = (IHTMLScriptElement)sElement.DomElement;

            scriptElement.text = scriptMethodCode;
            this.Document.Body.AppendChild(sElement);
        }
Example #18
0
        public void AvoidWebBrowserUnfriendlyJavaScript()
        {
            HtmlElement        sElement      = this.Document.CreateElement("script");
            IHTMLScriptElement scriptElement = (IHTMLScriptElement)sElement.DomElement;

            scriptElement.text = "alert = function(){};confirm = function(){};";
            this.Document.Body.AppendChild(sElement);
        }
Example #19
0
        private void loadScript()
        {
            HtmlElement        head     = browser.Document.GetElementsByTagName("head")[0];
            HtmlElement        scriptEl = browser.Document.CreateElement("script");
            IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;

            element.text = script;
            head.AppendChild(scriptEl);
        }
Example #20
0
        public void H_jsExecute(string js, HtmlDocument doc)
        {
            js = js.Replace(@"\\", "");
            HtmlElement        scriptElement = doc.CreateElement("script");
            IHTMLScriptElement element       = (IHTMLScriptElement)scriptElement.DomElement;

            element.text = "" + js + "";
            doc.GetElementsByTagName("head")[0].AppendChild(scriptElement);
        }
Example #21
0
 private static void AddScriptToHead(HTMLDocumentClass htmlDocument, IHTMLScriptElement script)
 {
     var headElementCollection = htmlDocument.getElementsByTagName(Head);
     foreach (IHTMLElement elem in headElementCollection)
     {
         var head = (HTMLHeadElementClass)elem;
         head.appendChild((IHTMLDOMNode)script);
     }
 }
Example #22
0
        private void AddCheckPageScript(IeRunWebBrowser webBrowser)
        {
            HtmlElement        sElement      = webBrowser.Document.CreateElement("script");
            IHTMLScriptElement scriptElement = (IHTMLScriptElement)sElement.DomElement;

            scriptElement.text = "function isOldPage(){return 'yes';};";
            webBrowser.Document.Body.AppendChild(sElement);
            string isOldPage = (string)this.RunPage.InvokeDoScriptMethod(webBrowser, "isOldPage", null);
        }
Example #23
0
        private void InjectScriptToHead(HTMLDocument doc, string script)
        {
            IHTMLDOMNode       head     = (IHTMLDOMNode)doc.getElementsByTagName("head").item(0);
            IHTMLScriptElement scriptEl = (IHTMLScriptElement)doc.createElement("script");

            scriptEl.type = "text/javascript";
            scriptEl.text = script;
            head.appendChild((IHTMLDOMNode)scriptEl);
        }
Example #24
0
        /// <summary>
        /// Adds the specified javascript to the HtmlDocument
        /// </summary>
        /// <param name="htmlDocument">The HtmlDocument</param>
        /// <param name="javaScript"></param>
        public static void AddScript(this HtmlDocument htmlDocument, string javaScript)
        {
            HtmlElement        head          = htmlDocument.GetElementsByTagName("head")[0];
            HtmlElement        scriptElement = htmlDocument.CreateElement("script");
            IHTMLScriptElement element       = (IHTMLScriptElement)scriptElement.DomElement;

            element.text = javaScript;
            head.AppendChild(scriptElement);
        }
Example #25
0
        public static void InjectScript(this WebBrowser webBrowser, string scriptData)
        {
            HtmlElement        body       = webBrowser.Document.GetElementsByTagName("body")[0];
            HtmlElement        scriptElem = webBrowser.Document.CreateElement("script");
            IHTMLScriptElement scriptDom  = (IHTMLScriptElement)scriptElem.DomElement;

            scriptDom.text = scriptData;
            body.AppendChild(scriptElem);
        }
        private void InjectJavaScript()
        {
            HtmlElement        head     = MainForm.currentBrowser.Document.GetElementsByTagName("head")[0];
            HtmlElement        scriptEl = MainForm.currentBrowser.Document.CreateElement("script");
            IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;

            element.text = rtbMain.Text;
            head.AppendChild(scriptEl);
        }
Example #27
0
        private void InjectAlertBlocker(WebBrowser webBrowser1)
        {
            HtmlElement        head         = webBrowser1.Document.GetElementsByTagName("head")[0];
            HtmlElement        scriptEl     = webBrowser1.Document.CreateElement("script");
            IHTMLScriptElement element      = (IHTMLScriptElement)scriptEl.DomElement;
            string             alertBlocker = "window.alert = function () { }";

            element.text = alertBlocker;
            head.AppendChild(scriptEl);
        }
Example #28
0
        private static void AddScriptToHead(HTMLDocumentClass htmlDocument, IHTMLScriptElement script)
        {
            var headElementCollection = htmlDocument.getElementsByTagName(Head);

            foreach (IHTMLElement elem in headElementCollection)
            {
                var head = (HTMLHeadElementClass)elem;
                head.appendChild((IHTMLDOMNode)script);
            }
        }
Example #29
0
        public void JavaScriptAlertMessage(WebBrowser pBrowser, string pMessage)
        {
            HtmlElement        vHead          = pBrowser.Document.GetElementsByTagName("head")[0];
            HtmlElement        vNewScriptTag  = pBrowser.Document.CreateElement("script");
            IHTMLScriptElement vScriptElement = (IHTMLScriptElement)vNewScriptTag.DomElement;

            vScriptElement.text = "function AlertMessage() { alert('" + pMessage + "'); }";
            vHead.AppendChild(vNewScriptTag);
            pBrowser.Document.InvokeScript("AlertMessage");
        }
Example #30
0
        private void textToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            HtmlElement        headElement   = view_f_browse.Document.GetElementsByTagName("head")[0];
            HtmlElement        scriptElement = view_f_browse.Document.CreateElement("script");
            IHTMLScriptElement element       = (IHTMLScriptElement)scriptElement.DomElement;

            element.text = "function tellwebdev() { return (document.selection.createRange().text) }";
            headElement.AppendChild(scriptElement);
            MessageBox.Show(view_f_browse.Document.InvokeScript("tellwebdev").ToString());
        }
Example #31
0
        private void InjectJavaScript()
        {
            HtmlElement        head    = Browser.Document.GetElementsByTagName("head")[0];
            HtmlElement        script  = Browser.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement)script.DomElement;

            element.text = "function hello() {alert(\"Yeah boy you did it\")}";
            head.AppendChild(script);
            Browser.Document.InvokeScript("hello");
        }
Example #32
0
        public void InjectJSScript(mshtml.HTMLDocument doc, IHTMLScriptElement JavaSCript)
        {
            IHTMLElementCollection nodes = doc.getElementsByTagName("head");

            foreach (IHTMLElement elem in nodes)
            {
                var head = (HTMLHeadElement)elem;
                head.appendChild((IHTMLDOMNode)JavaSCript);
            }
        }
        private void SetCookie()
        {
            HtmlElement        head    = Browser.Document.GetElementsByTagName("head")[0];
            HtmlElement        script  = Browser.Document.CreateElement("script");
            IHTMLScriptElement element = (IHTMLScriptElement)script.DomElement;

            element.text = "function setCookie() { document.cookie = 'ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=osapi.dmm.com;path=/'; document.cookie = 'ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=203.104.209.7;path=/'; document.cookie = 'ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=www.dmm.com;path=/netgame/'; document.cookie = 'ckcy=1;expires=Sun, 09 Feb 2019 09:00:09 GMT;domain=log-netgame.dmm.com;path=/';}";
            head.AppendChild(script);
            Browser.Document.InvokeScript("setCookie");
        }
Example #34
0
        public AcceptLinkClickScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            // This function is called when the user clicks the YES, LOG ME IN link
            builder.Append("function accept_click(){");
            builder.Append("set_cookie_cache();");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #35
0
        public DeclineLinkClickScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            // This function is called when the user clicks the NO THANKS link
            builder.Append("function decline_click(){");
            builder.Append("set_cookie_cache();");
            builder.Append("slideup('buy4_notice');");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #36
0
        public SlideUpScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("function slideup(objname){");
            builder.Append("if(moving[objname])");
            builder.Append("return;");
            builder.Append("if(document.getElementById(objname).style.display == 'none')");
            builder.Append("return;");
            builder.Append("moving[objname] = true;");
            builder.Append("dir[objname] = 'up';");
            builder.Append("startslide(objname);");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #37
0
        public Buy4CustomJavaScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            // This is the Buy4 Custom JavaScript content
            builder.Append("var timerlen = 10;");
            builder.Append("var slideAniLen = 750;");
            builder.Append("var timerID = new Array();");
            builder.Append("var startTime = new Array();");
            builder.Append("var obj = new Array();");
            builder.Append("var endHeight = new Array();");
            builder.Append("var moving = new Array();");
            builder.Append("var dir = new Array();");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #38
0
        public StartSlideScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("function startslide(objname){");
                builder.Append("obj[objname] = document.getElementById(objname);");
                builder.Append("endHeight[objname] = parseInt(obj[objname].style.height);");
                builder.Append("startTime[objname] = (new Date()).getTime();");
                builder.Append("if(dir[objname] == 'down'){");
                    builder.Append("obj[objname].style.height = '1px';");
                builder.Append("}");

                builder.Append("obj[objname].style.display = 'block';");
                builder.Append("timerID[objname] = setInterval('slidetick(\"' + objname + '\");',timerlen);");

            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #39
0
        public GetCookieScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            // This function returns the value of the cookie
            builder.Append("function get_cookie(name){");
                builder.Append("var cookies = document.cookie;");
                builder.Append("if( cookies.indexOf(name) != -1 )");
                    builder.Append("{");
                    builder.Append("var startpos = cookies.indexOf(name) + name.length + 1;");
                    builder.Append("var endpos = cookies.indexOf(';',startpos);");
                    builder.Append("if( endpos == -2 ) endpos = cookies.length;");
                    builder.Append("return unescape(cookies.substring(startpos,endpos));");
                    builder.Append("}");
                builder.Append("else { return 'false'; }");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #40
0
        public SetCookieCacheScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            // This function is called when the user clicks either response
            // It prevents the notification for 1 day
            builder.Append("function set_cookie_cache(){");
                // This portion constructs the expire date for the cookie...
                builder.Append("var expire_date = new Date();");
                builder.Append("expire_date.setDate(expire_date.getDate() + 1);");
                // This portion constructs the domain for the cookie...
                builder.Append("var domain_array = new Array();");
                builder.Append("domain_array = location.href.split(\".\");");
                builder.Append("domain_array.reverse();");
                builder.Append("var domain = domain_array[1] + \".\" + domain_array[0];");
            builder.Append("domain = domain.replace(\"/\",\"\");");
                builder.Append("document.cookie = 'buy4_cache=true; expires=' + expire_date.toGMTString() + '; domain=.' + domain + '; path=/';");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.text = builder.ToString();
            _script.type = "text/javascript";
        }
Example #41
0
        public EndSlideScript(HTMLDocument Document)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("function endSlide(objname){");
                builder.Append("clearInterval(timerID[objname]);");
                builder.Append("if(dir[objname] == 'up')");
                    builder.Append("obj[objname].style.display = 'none';");

                builder.Append("obj[objname].style.height = endHeight[objname] + 'px';");
                builder.Append("delete(moving[objname]);");
                builder.Append("delete(timerID[objname]);");
                builder.Append("delete(startTime[objname]);");
                builder.Append("delete(endHeight[objname]);");
                builder.Append("delete(obj[objname]);");
                builder.Append("delete(dir[objname]);");

                builder.Append("return;");
            builder.Append("}");

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";
            _script.text = builder.ToString();
        }
Example #42
0
        public JavascriptNode(HTMLDocument Document,config Config,Store Store)
        {
            StringBuilder builder = new StringBuilder();
            IHTMLElement notice_div = (IHTMLElement) new NoticeDiv(Document, Config, Store).NoticeDivDomNode;

            _script = (IHTMLScriptElement) Document.createElement("script");
            _script.type = "text/javascript";

            _script.text += (new GetCookieScript(Document).ToString());
            _script.text += (new SetCookieCacheScript(Document).ToString());

            // This script inserts the Buy4 notice into the DOM
            /*
            builder.Append("var notice = document.createElement(\"span\");");
            builder.Append("notice.id = \"container_div\";");

            builder.Append("notice.style.position =\"absolute\";");
            builder.Append("notice.style.top = \"10px\";");
            builder.Append("notice.style.align = \"center\";");
            builder.Append("notice.style.left = \"10px\";");
            builder.Append("notice.style.width = \"97%\";");
            builder.Append("notice.style.height = \"auto\";");
            builder.Append("notice.style.zIndex = \"1000\";");
            builder.Append(String.Format("notice.innerHTML= '{0}';", notice_div.outerHTML.Replace(Environment.NewLine, "")));
            */

            /*
            builder.Append("alert(get_cookie(\"buy4_cache\"));");
            */
            /*
            builder.Append("if( get_cookie(\"buy4_cache\") != \"true\" )");
            builder.Append("{ document.body.appendChild(notice); }");
            */

            _script.text = builder.ToString();
        }