Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle clicks on Links in Python with Gtk 3.0 and WebKit2 4.0?

I have created my view (wrapped in a window) and loaded an URL like this:

self.web_view = WebKit2.WebView()
self.web_view.load_uri("https://en.wikipedia.org")

My "Mini-Browser" starts and I can click on local links (links which are bound to JavaScript events or links to other pages on the same domain). But when the links point to other domains, nothing happens. How do I catch clicks on external links? Or how can I open these links in the system default browser?

UPDATE: Cross site links are not handled by the "Mini-Browser". Can I write an event hook(onclick) to interrupt the "Mini-Browser" and act based on custom logic or is there a way to configure cross-site links.

like image 827
Witek Avatar asked Jul 26 '16 14:07

Witek


1 Answers

Did you use a GtkLinkButton ? According to the doc of gtk-show-uri which uses the default-browser to open links, you additionally need to install the gvfs to get support for uri schemes such as http:// or ftp://

For debian based distributions you can install gvfs just like that:

sudo apt-get install gvfs gvfs-backends gvfs-fuse

If that does not help, you additionally can check the error-message of gtk_show_uri, in case it returns FALSE

For custom-browsers, like yours, according to the doc of GtkLinkButton you need to connect to the activate-link signal and return true from the handler ... probably you already did so.

like image 126
Alex Avatar answered Oct 05 '22 01:10

Alex