From 841cb5f34af269264a755ee35d7a372e17807526 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Sat, 20 May 2017 18:49:08 +0200 Subject: [PATCH] hints: use `window.location.href` to change current URL When opening a hint in the current window, we do so by emulating a `click()` on the element that we want to switch to. This enables us to open hints when there is no href set, e.g. when the element executes JavaScript to change the page. Unfortunately, this method of opening links does not work when JavaScript is disabled in the client. If the element has a `href` attribute, we can work around this problem by directly setting `window.location.href` to the element's reference. Next to being a more obvious method of setting the current URL, this also fixes hints with JavaScript disabled. Note that we still have to keep around the old method of using `click()` on the element in case it has no href attribute. --- src/scripts/hints.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/scripts/hints.js b/src/scripts/hints.js index 0c13644..ceb86ed 100644 --- a/src/scripts/hints.js +++ b/src/scripts/hints.js @@ -387,15 +387,19 @@ var hints = Object.freeze((function(){ /* We call open() and click() in async mode to avoid return as fast as possible. */ /* If we don't return immediately, the EvalJS dbus call will probably timeout and cause */ /* errors. */ - if (newWin && e.hasAttribute('href')) { - /* Since the "noopener" vulnerability thing, it's not possible to set an anchor's */ - /* target to _blank. Therefore, we can't simulate ctrl-click through _blank like we */ - /* used to. Therefore, we limit ourselves to "window.open()" in cases we're firing a */ - /* simple link. In other cases, we fire the even normally. */ - window.setTimeout(function() { - window.open(e.getAttribute('href'), '_blank'); - }, 0 - ); + if (e.hasAttribute('href')) { + if (newWin) { + /* Since the "noopener" vulnerability thing, it's not possible to set an anchor's */ + /* target to _blank. Therefore, we can't simulate ctrl-click through _blank like we */ + /* used to. Therefore, we limit ourselves to "window.open()" in cases we're firing a */ + /* simple link. In other cases, we fire the even normally. */ + window.setTimeout(function() { + window.open(e.getAttribute('href'), '_blank'); + }, 0 + ); + } else { + window.location.href = e.getAttribute('href'); + } } window.setTimeout(function() {e.click();}, 0); } -- 2.20.1