deal with onclick handlers that don't return false

Because <base> is set to the media server URL, <a href='#' ...> causes
a page transition from the current setHtml() page data. Previous Qt
versions allowed us to just ignore the request, but now returning False
in acceptNavigationRequest() causes the subsequent page navigation to
be rejected as well, resulting in no visible change when clicking on a
deck in the deck list.

To deal with this, Anki will now warn when such navigation requests
come in, as the anchors need to be updated to return false. pycmd()
has been updated to return false to make returning in onclick easier.

Also use QUrl.matches() instead of converting the potentially long
URL to a string.
This commit is contained in:
Damien Elmes 2018-10-23 16:47:01 +10:00
parent fa9a54db98
commit 14f4107dfd
2 changed files with 6 additions and 4 deletions

View file

@ -176,7 +176,7 @@ where id > ?""", (self.mw.col.sched.dayCutoff-86400)*1000)
buf += """
<td class=decktd colspan=5>%s%s<a class="deck %s"
href=# onclick="pycmd('open:%d')">%s</a></td>"""% (
href=# onclick="return pycmd('open:%d')">%s</a></td>"""% (
indent(), collapse, extraclass, did, name)
# due counts
def nonzeroColour(cnt, colour):

View file

@ -49,7 +49,8 @@ class AnkiWebPage(QWebEnginePage):
}
}
channel.objects.py.cmd(arg, resultCB);
channel.objects.py.cmd(arg, resultCB);
return false;
}
pycmd("domDone");
});
@ -71,9 +72,10 @@ class AnkiWebPage(QWebEnginePage):
# data: links generated by setHtml()
if url.scheme() == "data":
return True
# catch buggy <a href='#' onclick='func()'> links
from aqt import mw
# ignore href=#
if url.toString().startswith(mw.serverURL()):
if url.matches(QUrl(mw.serverURL()), QUrl.RemoveFragment):
sys.stderr.write("onclick handler needs to return false\n")
return False
# load all other links in browser
openLink(url)