From 24e5c07ac97d24aaa7d579eb34c1851afbd731bb Mon Sep 17 00:00:00 2001 From: Danish Prakash Date: Mon, 24 Jan 2022 07:53:01 +0530 Subject: [PATCH] qt/aqt/webview: handle opening href with target=_blank (#1623) * qt/aqt/webview: handle opening href with target=_blank * CONTRIBUTORS: add username as part of first PR --- CONTRIBUTORS | 1 + qt/aqt/webview.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f3e847ba7..8151602f9 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -91,6 +91,7 @@ git9527 Vova Selin qxo <49526356@qq.com> Spooghetti420 +Danish Prakash ******************** diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index 21bd22663..6351267e7 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -259,6 +259,11 @@ class AnkiWebView(QWebEngineView): def disable_zoom(self) -> None: self._disable_zoom = True + def createWindow(self, windowType: QWebEnginePage.WebWindowType) -> QWebEngineView: + # intercept opening a new window (hrefs + # with target="_blank") and return view + return AnkiWebView() + def eventFilter(self, obj: QObject, evt: QEvent) -> bool: if self._disable_zoom and is_gesture_or_zoom_event(evt): return True