From 989e3b7291f34ec7f560a1293124aab71ba9aa62 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 30 May 2015 13:56:36 -0400 Subject: [PATCH] Added a fallback for when JavaScript is disabled. --- qutebrowser/browser/commands.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index bc3931a65..17ef07196 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -25,7 +25,9 @@ import shlex import subprocess import posixpath import functools +from xml.etree import ElementTree +from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWidgets import QApplication, QTabBar from PyQt5.QtCore import Qt, QUrl, QEvent from PyQt5.QtGui import QClipboard, QKeyEvent @@ -985,7 +987,8 @@ class CommandDispatcher: url = objreg.get('quickmark-manager').get(name) self._open(url, tab, bg, window) - @cmdutils.register(instance='command-dispatcher', name='select-follow', scope='window') + @cmdutils.register(instance='command-dispatcher', name='select-follow', + scope='window') def select_follow(self, tab=False): """Follow the selected text. @@ -993,9 +996,19 @@ class CommandDispatcher: tab: Load the selected link in a new tab. """ widget = self._current_widget() - if tab: - widget.page().open_target = usertypes.ClickTarget.tab - widget.page().currentFrame().evaluateJavaScript('window.getSelection().anchorNode.parentNode.click()') + if QWebSettings.globalSettings().testAttribute( + QWebSettings.JavascriptEnabled): + if tab: + widget.page().open_target = usertypes.ClickTarget.tab + widget.page().currentFrame().evaluateJavaScript( + 'window.getSelection().anchorNode.parentNode.click()') + else: + selected_element = ElementTree.fromstring( + '' + widget.selectedHtml() + '').find('a') + if selected_element is not None: + url = selected_element.attrib['href'] + if url: + self._open(QUrl(url), tab) @cmdutils.register(instance='command-dispatcher', name='inspector', scope='window')