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
This commit is contained in:
Danish Prakash 2022-01-24 07:53:01 +05:30 committed by GitHub
parent 62fd5b2b42
commit 2c357a6c94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -91,6 +91,7 @@ git9527 <github.com/git9527>
Vova Selin <vselin12@gmail.com> Vova Selin <vselin12@gmail.com>
qxo <49526356@qq.com> qxo <49526356@qq.com>
Spooghetti420 <github.com/spooghetti420> Spooghetti420 <github.com/spooghetti420>
Danish Prakash <github.com/danishprakash>
******************** ********************

View file

@ -259,6 +259,11 @@ class AnkiWebView(QWebEngineView):
def disable_zoom(self) -> None: def disable_zoom(self) -> None:
self._disable_zoom = True 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: def eventFilter(self, obj: QObject, evt: QEvent) -> bool:
if self._disable_zoom and is_gesture_or_zoom_event(evt): if self._disable_zoom and is_gesture_or_zoom_event(evt):
return True return True