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: