How can i expose an Microsoft web Browser control embed in QAxWidget to javascript ?



  • Hello,
    I am a new Qt learner ,i need to write some application program use GoogleEarth API in recently , the trick for this work is to load the Earth in a web browser and in the web page's JavaScript call the function of the win form which have been exposed to com object,and vice versa.
    The problem is that when I use QWebView load the html file,the Google earth plug-in post the message that the browser is not support Google Earth plug-in.Because I have successfully make it in VB.NET,C# and MFC,but my boss not allow me to use these approach and force me to use Qt. So the only way I can think out is to use ActiveX control in Qt application.In MFC program i do it like this:
    Use CHtmlView as the base class of a win from and expose win from method to javascript use this micro:

    @
    BEGIN_DISPATCH_MAP(CVirtualEarthView, CHtmlView)
    DISP_FUNCTION(CVirtualEarthView, "winMessage", OnWinMessage, VT_EMPTY, VTS_BSTR)
    ...
    END_DISPATCH_MAP()
    @

    then in javascript i can call win from's method like this: window.external.winMessage("Hello!")
    In c# like this :

    @
    [comvisiable(true)]
    class GeForm
    {
    private System.Windows.Forms.WebBrowser wndWebView;
    public GeForm()
    {
    //...
    this.wndWebView.ObjectForScripting = this;
    }
    //....
    public void Msg(sting)
    {
    MessageBox.Show(msg);
    }
    }
    @

    also call the win from's method in javaScript use
    @
    window.external.Msg("hello")
    ...
    @
    When use QWebView , i can also do it via the QWebFrame's addToJavaScriptWindowObject method
    @
    ui.wndWebView->page()->mainFrame()->addToJavaScriptWindowObject("winForm", this);
    @
    but when i use the ActiveX control of Microsoft web Browser to instead QWebView,i really don't know how to do it ,so is there any one can give me some help?

    [EDIT: code formatting, please wrap in @-tags, Volker]



  • Have you tried to stick to WebKit and just fake the user agent?



  • Thank edit,it's really a beautiful presentation of code,thank you for your tip!

    And Lukas can you give me something more detailed? thanks.



  • What about your means "fake the agent"? thanks
    [quote author="Lukas Geyer" date="1319817179"]Have you tried to stick to WebKit and just fake the user agent?[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.