Browse Source

main.js: fix empty window opened in some cases (#5146)

Fixes the following problem:

1. Don't have any article selected (easiest by clicking on "main stream" or a category)
2. Press space
3. A blank window is opened, but since there's no link nothing else happens.
Frans de Jonge 3 years ago
parent
commit
e56ecf79f6
1 changed files with 7 additions and 5 deletions
  1. 7 5
      p/scripts/main.js

+ 7 - 5
p/scripts/main.js

@@ -1013,11 +1013,13 @@ function init_shortcuts() {
 			}
 
 			const link_go_website = document.querySelector('.flux.current a.go_website');
-			const newWindow = window.open();
-			if (link_go_website && newWindow) {
-				newWindow.opener = null;
-				newWindow.location = link_go_website.href;
-				ev.preventDefault();
+			if (link_go_website) {
+				const newWindow = window.open();
+				if (newWindow) {
+					newWindow.opener = null;
+					newWindow.location = link_go_website.href;
+					ev.preventDefault();
+				}
 			}
 			return;
 		}