hints: use `window.location.href` to change current URL
authorPatrick Steinhardt <ps@pks.im>
Sat, 20 May 2017 16:49:08 +0000 (18:49 +0200)
committerPatrick Steinhardt <ps@pks.im>
Sat, 20 May 2017 16:49:08 +0000 (18:49 +0200)
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

index 0c13644..ceb86ed 100644 (file)
@@ -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 <a> 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 <a> 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);
     }