简体   繁体   中英

c# AxWebBrowser Document OnClick Disables browser

It seems like there is a lot of questions like this, but cant find the answer.

I've implemented OnClick event like it this thread: http://support.microsoft.com/?kbid=312777 But the result is that browser is completely disabled (scrollbar, controls...).

I've searcher the internet and couldn't find clear solution.

Some says that has to be created new class inherited from WsbBrowser and then overload those events. Other says that answer is here http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_20661377.html but i dont have account.

 private void FormBrowser_DocumentComplete(object sender, DWebBrowserEvents2_DocumentCompleteEvent e)
    {
        mshtml.HTMLDocument doc;
        doc = (mshtml.HTMLDocument)FormBrowser.Document;
        mshtml.HTMLDocumentEvents2_Event iEvent;
        iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
        iEvent.onclick += new HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
    }

private bool ClickEventHandler(mshtml.IHTMLEventObj e)
    {
        return true;
    }

Who knows solution?

Well i've found a way how to handle onclick events for AxWebBrowser HTML elements. Here is what you need to do:

First we need to create a dispatcher class:

public class DispatcherSketchClass
    {
        public DispatcherSketchClass()
        {
        }
        [DispId(0)]
        public void DefaultMethod()
        {
        //this method will be called
        }
    }

Then we just attach this dispather to some element:

 void AddDispatcher(AxWebBrowser browser)
        {
            IHTMLDocument2 doc = (IHTMLDocument2)browser.Document;

            foreach (IHTMLElement VARIABLE in doc.all)
            {
                //find right element
                if (VARIABLE.title == "the name")
                {
                    // attach here               
                    DispatcherClass dp = new DispatcherClass();
                    VARIABLE.onclick = dp;
                }

            }
         }

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM