Reputation: 9496
Android lets you add a Javascript Interface, that will let you use "window.interfacename.myfunction()" to call a function in the Java program.
Is there any similar feature that allows a PyGTK with embedded webkit browser to have similar functionality, to call a specific Python function from Javascript?
Upvotes: 2
Views: 258
Reputation: 9496
I ended up adding a handler for special urls. I overrode the webkit with:
webview.connect("navigation-policy-decision-requested", self.webkitGo)
where self.webkitGo is the name of the function: def webkitGo(self, view, frame, net_req, nav_act, pol_dec):
In this function, you can receive the url data from net_req.get_uri()
and decide what to do with it, and return true to not do the default behavior.
Upvotes: 1
Reputation: 57880
You can do it in C using the JavaScriptCore library that comes with WebKit. I don't know any examples in PyGTK, but I assume that JavaScriptCore is available through GObject Introspection.
Upvotes: 1