Handle links with a target in the standalone viewer

This commit is contained in:
Kovid Goyal 2019-08-30 07:21:47 +05:30
parent 566bfe6df2
commit c7a2178d24
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -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):

View File

@ -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