From c7a2178d241de9a3e04ec035f84270b262ec1294 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 30 Aug 2019 07:21:47 +0530 Subject: [PATCH] Handle links with a target in the standalone viewer --- src/calibre/gui2/viewer/web_view.py | 3 ++- src/pyj/read_book/iframe.pyj | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 676674ab45..f31a336d49 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -279,7 +279,8 @@ class WebPage(QWebEnginePage): return True if url.scheme() in (FAKE_PROTOCOL, 'data'): return True - safe_open_url(url) + if url.scheme() in ('http', 'https'): + safe_open_url(url) return False def go_to_anchor(self, anchor): diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index a27ce96ad3..58854b768c 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -15,7 +15,7 @@ from read_book.flow_mode import ( ) from read_book.footnotes import is_footnote_link from read_book.globals import ( - current_book, current_layout_mode, current_spine_item, set_boss, + current_book, current_layout_mode, current_spine_item, runtime, set_boss, set_current_spine_item, set_layout_mode ) from read_book.mathjax import apply_mathjax @@ -380,6 +380,10 @@ class IframeBoss: link_attr = 'data-' + self.book.manifest.link_uid for a in document.body.querySelectorAll('a[{}]'.format(link_attr)): a.addEventListener('click', self.link_activated) + if runtime.is_standalone_viewer: + # links with a target get turned into requests to open a new window by Qt + for a in document.body.querySelectorAll('a[target]'): + a.removeAttribute('target') def link_activated(self, evt): link_attr = 'data-' + self.book.manifest.link_uid