Beispiel #1
0
            private void injectScripts()
            {
                // Thanks to: http://stackoverflow.com/questions/7998996/how-to-inject-javascript-in-webbrowser-control
                HtmlElement head     = _webBrowser.Document.GetElementsByTagName("head")[0];
                HtmlElement scriptEl = _webBrowser.Document.CreateElement("script");

                mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement;
                element.src = "http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/release/javascript-xpath-latest-cmp.js";
                head.AppendChild(scriptEl);
                string javaScriptText = @"
                        function GetElements (XPath) {
                                var xPathRes = document.evaluate ( XPath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);              
                                var nextElement = xPathRes.iterateNext ();
                                var elements = new Object();
                                var elementIndex = 1;
                                while (nextElement) {
                                elements[elementIndex++] = nextElement;
                                nextElement = xPathRes.iterateNext ();
                                }
                            elements.length = elementIndex -1;
                            return elements;
                            };
                       ";

                scriptEl     = _webBrowser.Document.CreateElement("script");
                element      = (mshtml.IHTMLScriptElement)scriptEl.DomElement;
                element.text = javaScriptText;
                head.AppendChild(scriptEl);
            }
Beispiel #2
0
        //private void CancelAlertWin()
        //{
        //    var doc = main_browser.Document.Window.Frames["wsyw_main_content_iframe"]?.Document;
        //    HtmlElement head = doc.GetElementsByTagName("head")[0];
        //    HtmlElement scriptEl = doc.CreateElement("script");
        //    mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement;
        //    string alertBlocker = "window.alert = function () { }";
        //    element.text = alertBlocker;
        //    head.AppendChild(scriptEl);
        //    wbNav.ScriptErrorsSuppressed = true;
        //}

        private void InjectAlertBlocker()
        {
            //var doc = main_browser.Document.Window.Frames["wsyw_main_content_iframe"]?.Document;
            //HtmlElement head = doc.GetElementsByTagName("head")[0];
            //HtmlElement scriptEl = doc.CreateElement("script");
            ////string alertBlocker = "window.alert = function () { }";
            //string alertBlocker = "CFW.oWin.fnAlert = function () { };window.alert = function () { }";
            ////string alertBlocker = "alert(1);";
            //scriptEl.SetAttribute("text", alertBlocker);
            //head.AppendChild(scriptEl);
            //doc.Body.AppendChild(scriptEl);
            //main_browser.Document.Body.AppendChild(scriptEl);


            var doc = main_browser.Document.Window.Frames["wsyw_main_content_iframe"]?.Document;
            //HtmlElement head = doc.GetElementsByTagName("head")[0];
            var         head     = doc.GetElementsByTagName("head")[0];
            HtmlElement scriptEl = doc.CreateElement("script");

            mshtml.IHTMLScriptElement element = (mshtml.IHTMLScriptElement)scriptEl.DomElement;
            string alertBlocker = "CFW.oWin.fnAlert = function () { };window.alert = function () { }";

            element.text = alertBlocker;
            head.AppendChild(scriptEl);
            doc.Body.AppendChild(scriptEl);
            main_browser.ScriptErrorsSuppressed = true;
        }
Beispiel #3
0
        private void frmBrowser_Navigated(object sender, NavigationEventArgs e)
        {
            SetStatusRight("RSS completely loaded.");
            WebBrowser Browser = sender as WebBrowser;

            mshtml.HTMLDocument       HTMLDoc    = Browser.Document as mshtml.HTMLDocument;
            mshtml.IHTMLScriptElement HTMLScript = (mshtml.IHTMLScriptElement)HTMLDoc.createElement("SCRIPT");
            HTMLScript.type = "text/javascript";
            HTMLScript.text = @"function noError() { return true; } window.onerror = noError;";
            mshtml.IHTMLElementCollection Nodes = HTMLDoc.getElementsByTagName("HEAD");
            foreach (mshtml.HTMLHeadElement HTMLElementItem in Nodes)
            {
                HTMLElementItem.appendChild((mshtml.IHTMLDOMNode)HTMLScript);
            }
        }
        /// <summary>
        /// Private control constructor defining all default values
        /// </summary>
        public HtmlEditorControl()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // define the default values
            // browser constants and commands
            EMPTY_PARAMETER = System.Reflection.Missing.Value;

            // default values used to reset values
            _defaultBodyBackColor = Color.White;
            _defaultBodyForeColor = Color.Black;
            _defaultBackColor = SystemColors.ControlLight;
            _defaultFont = new HtmlFontProperty(this.Font);

            // define the default values of the properties
            _readOnly = false;
            _toolbarVisible = true;
            _toolbarDock = DockStyle.Bottom;
            _bodyText = DEFAULT_HTML_TEXT;
            _bodyHtml = DEFAULT_HTML_TEXT;
            _bodyBackColor = _defaultBodyBackColor;
            _bodyForeColor = _defaultBodyForeColor;
            _bodyFont = _defaultFont;
            _scrollBars = DisplayScrollBarOption.Auto;
            _imageDirectory = string.Empty;
            _htmlDirectory = string.Empty;
            _navigateWindow = NavigateActionOption.Default;
            _baseHref = string.Empty;
            _autoWordWrap = true;
            _borderSize = DEFAULT_BORDER_SIZE;
            stylesheet = null;
            script = null;

            // define context menu state and size
            this.BackColor = _defaultBackColor;
            this.contextDocumentToolbar.Checked = true;
            this.contextDocumentScrollbar.Checked = true;
            this.contextDocumentWordwrap.Checked = true;
            SetBrowserPanelSize();

            // load the blank Html page to load the MsHtml object model
            BrowserCodeNavigate(BLANK_HTML_PAGE);

            // after load ensure document marked as editable
            this.ReadOnly = _readOnly;
            this.ScrollBars = _scrollBars;
        }
Beispiel #5
0
        public HtmlEditorControl()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // define the context menu for format commands
            DefineFormatBlockMenu();

            // define the default values
            // browser constants and commands
            EMPTY_PARAMETER = System.Reflection.Missing.Value;

            // default values used to reset values
            _defaultBackColor = Color.White;
            _defaultForeColor = Color.Black;
            _defaultFont = new HtmlFontProperty(this.Font);

            // set browser default values to hide IE items
            this.editorWebBrowser.AddressBar = false;
            this.editorWebBrowser.MenuBar = false;
            this.editorWebBrowser.StatusBar = false;

            // obtain the underlying web browser and set options
            // SHDocVw.WebBrowser webBrowser = (SHDocVw.WebBrowser)this.editorWebBrowser.GetOcx();

            // define the default values of the properties
            _readOnly = false;
            _toolbarVisible = false;
            _enableVisualStyles = false;
            _toolbarDock = DockStyle.Bottom;
            _bodyText = DEFAULT_HTML_TEXT;
            _bodyHtml = DEFAULT_HTML_TEXT;
            _bodyBackColor = _defaultBackColor;
            _bodyForeColor = _defaultForeColor;
            _bodyFont = _defaultFont;
            _scrollBars = DisplayScrollBarOption.Auto;
            _imageDirectory = string.Empty;
            _htmlDirectory = string.Empty;
            _navigateWindow = NavigateActionOption.Default;
            _baseHref = string.Empty;
            _autoWordWrap = true;
            stylesheet = null;
            script = null;

            // define context menu state
            this.menuDocumentToolbar.Checked = true;
            this.menuDocumentScrollbar.Checked = true;
            this.menuDocumentWordwrap.Checked = true;

            // load the blank Html page to load the MsHtml object model
            BrowserCodeNavigate(BLANK_HTML_PAGE);

            // after load ensure document marked as editable
            this.ReadOnly = _readOnly;
        }
Beispiel #6
0
 // define a script element that is to be used by all documents
 // can be sued for document processing
 public void LinkScriptSource(string scriptSource)
 {
     if (script != null)
     {
         script.src = scriptSource;
     }
     else
     {
         // create the script element
         script = (HtmlScriptElement)document.createElement(SCRIPT_TAG);
         script.src = scriptSource;
         script.defer = true;
         // insert into the document
         HtmlDomNode node = (HtmlDomNode)document.documentElement;
         node.appendChild((HtmlDomNode)script);
     }
 }