From 72609bee189e8c45056d2773ab50b50242eb3034 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 29 Jun 2020 13:49:35 +1000 Subject: [PATCH] add option to webview to skip external browser open --- qt/aqt/webview.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index bef02d634..814ad2d0e 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -26,6 +26,7 @@ class AnkiWebPage(QWebEnginePage): QWebEnginePage.__init__(self) self._onBridgeCmd = onBridgeCmd self._setupBridge() + self.open_links_externally = True def _setupBridge(self): class Bridge(QObject): @@ -98,6 +99,9 @@ class AnkiWebPage(QWebEnginePage): sys.stdout.write(buf) def acceptNavigationRequest(self, url, navType, isMainFrame): + if not self.open_links_externally: + return super().acceptNavigationRequest(url, navType, isMainFrame) + if not isMainFrame: return True # data: links generated by setHtml() @@ -238,6 +242,9 @@ class AnkiWebView(QWebEngineView): return False return False + def set_open_links_externally(self, enable: bool) -> None: + self._page.open_links_externally = enable + def onEsc(self): w = self.parent() while w: