Esempio n. 1
0
        void SinkScriptErrorEvents()
        {
            // Grab the document object off of the Web Browser control
            IHTMLDocument2 document = (IHTMLDocument2)Browser.Document;

            if (document == null)
            {
                return;
            }

            // Grab the window object off of the document object
            HTMLWindow2 window = (HTMLWindow2)document.parentWindow;

            if (window == null)
            {
                return;
            }

            // Cast the window object to the window events interface
            HTMLWindowEvents2_Event windowEvents = (HTMLWindowEvents2_Event)window;

            if (windowEvents == null)
            {
                return;
            }

            // Attach to the error event on the window object; this
            // will be sent a notification when a script error occurs
            windowEvents.onerror += Browser_HTMLWindowEvents2_OnError;
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        private void Explorer_DownloadComplete()
        {
            HTMLDocument doc = this.Explorer.Document as HTMLDocument;

            if (doc != null)
            {
                IHTMLWindow2 tmpWindow = doc.parentWindow;
                if (tmpWindow != null)
                {
                    HTMLWindowEvents2_Event events = (tmpWindow as HTMLWindowEvents2_Event);
                    try
                    {
                        events.onload -= new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                    }
                    catch { }
                    events.onload += new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                }
            }
        }
Esempio n. 4
0
        private void htmlNavigateComplete(object sender, BrowserNavigateComplete2Event e)
        {
            string url = e.url;

            Trace.WriteLine("htmlNavigateComplete(): " + e.url);
            bool rootPage = e.IsRootPage;

            if (rootPage)
            {
                if (url != "about:blank")
                {
                    textUrl.Text = url;
                }
                htmlControl1.Focus();
            }

            HTMLWindowEvents2_Event window = (HTMLWindowEvents2_Event)htmlControl1.Document2.GetParentWindow();

            window.onerror += this.WindowError;
        }
Esempio n. 5
0
        public virtual void ModifyDOM(IHTMLDocument2 document, bool addEventHandler)
        {
            ((IHTMLDocument3)document).documentElement.insertAdjacentHTML("afterBegin", "<script language='javascript' type='text/css'>window.onerror = function(e){return true;}</script>");
            ((IHTMLDocument3)document).documentElement.insertAdjacentHTML("afterBegin", "<script language='javascript'>window.alert = function () { }</script>");

            IHTMLDocument3 doc = (IHTMLDocument3)document;

            IHTMLElementCollection linkElements = doc.getElementsByTagName("LINK");

            foreach (IHTMLLinkElement linkElement in linkElements)
            {
                linkElement.disabled = true;
            }

            //Also disable style elements, so that @import inside styles won't trigger download.
            IHTMLElementCollection styleElements = doc.getElementsByTagName("STYLE");

            foreach (IHTMLStyleElement styleElement in styleElements)
            {
                styleElement.disabled = true;
            }

            //BrowserOptions.NoFrameDownload seems to work only for FRAME elements and not the IFRAME elements.
            IHTMLElementCollection iframeElements = doc.getElementsByTagName("IFRAME");

            foreach (IHTMLElement iframeElement in iframeElements)
            {
                //iframeElement.setAttribute("src", "about:blank");
            }

            if (addEventHandler)
            {
                HTMLWindowEvents2_Event onErrorEvent = (HTMLWindowEvents2_Event)document.parentWindow;

                onErrorEvent.onerror += myHTMLWindowEvents2_onerror;
            }
        }
Esempio n. 6
0
        private void ieInstance_DownloadComplete()
        {
            HTMLDocument doc = this.ieInstance.Document as HTMLDocument;

            if (doc != null)
            {
                IHTMLWindow2 tmpWindow = doc.parentWindow;
                if (tmpWindow != null)
                {
                    HTMLWindowEvents2_Event events = (tmpWindow as HTMLWindowEvents2_Event);
                    try
                    {
                        //if (events != null)
                        {
                            events.onload -= new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    events.onload += new HTMLWindowEvents2_onloadEventHandler(RefreshHandler);
                }
            }
        }