webview - is it possible to retrieve event handles from java script

222 views
Skip to first unread message

nida2010

unread,
Jan 28, 2013, 12:55:33 PM1/28/13
to wx-u...@googlegroups.com
Hi everybody,

the WebView class is really nice to use. However, do you have any idea for the following?

Problem

I want to use WebView and display html content. Instead of using default
wxbuttons I would like to use buttons within the html page and when I pressing a 
button, e.g. close the window (behind with java script), I want to take over the 
command to wxwidgets.

Question

- Is this possible to realize with wxwidgets?
- And if yes, do you have any suggestions how to implement it?

Many thanks in advance,
Daniel

Steven Lamerton

unread,
Jan 29, 2013, 3:36:48 AM1/29/13
to wx-u...@googlegroups.com
On 28 January 2013 17:55, nida2010 <funk....@web.de> wrote:
Problem

I want to use WebView and display html content. Instead of using default
wxbuttons I would like to use buttons within the html page and when I pressing a 
button, e.g. close the window (behind with java script), I want to take over the 
command to wxwidgets.

Question

- Is this possible to realize with wxwidgets?
- And if yes, do you have any suggestions how to implement it?

Hi,

Unfortunately this isn't possible at the moment. There has been some work on implementing this for the wxGTK/Webview backend but it isn't yet merged into the trunk and would only work for that particular backend. 

Similar work would be possible under wxMSW/IE but no one is working on it as far as I know. If you were interesting in working on it that would of course be most appreciated.

Hope that helps,

Steven

Andrea Zanellato

unread,
Jan 29, 2013, 6:00:26 AM1/29/13
to wx-u...@googlegroups.com
I think it should be nice to have some API interface in wxWebView to support some external 'wxJS' library in a plugin model.
The concept could be the same as wx code has support for wxPython, having 'wxJS' as a stand alone javascript wrapper/binding library.
From the 'wxJS' point of view, the js engine could be implemented in the same backend model like wxWebView/wxMediaCtrl have, wrapping different javascripts external libraries (Nitro, SpiderMonkey, V8...).

Auria

unread,
Jan 29, 2013, 5:47:39 PM1/29/13
to wx-u...@googlegroups.com
Hi,

I think this trick may work. Register a custom URL scheme as described in the documentation (RegisterHandler). Then make an ajax request to this scheme (e.g. with jQuery.ajax). If all goes well the handler will see your request.

If this fails, maybe you can just request some dummy file but include parameters in the request URL, normally webview gives you an event for each request so you would see the request going too

-- Auria

TcT

unread,
Feb 4, 2013, 7:47:28 AM2/4/13
to wx-u...@googlegroups.com
What I did successfully under Windows and OSX (don't know about other platforms) is use the
wxEVT_COMMAND_WEB_VIEW_NAVIGATING event.
When the event is triggered I check for a custom url scheme e.g. buttonclick://button/1 if it matches I veto() the event or Skip it otherwise. In the javascript code I simple call window.location = 'buttonclick://button/1' to trigger the callback.
Reply all
Reply to author
Forward
0 new messages