diff --git a/vnc_auto.html b/vnc_auto.html
index 2aa2188978d03f444c71cff9a82db863d0227509..7704bf69dd2ffbb34aef860fc4c37098f3ed6c10 100644
--- a/vnc_auto.html
+++ b/vnc_auto.html
@@ -2,7 +2,7 @@
 <html>
 <head>
 
-    <!-- 
+    <!--
     noVNC example: simple example using default UI
     Copyright (C) 2012 Joel Martin
     Copyright (C) 2013 Samuel Mannehed for Cendio AB
@@ -128,12 +128,12 @@
             // if port == 80 (or 443) then it won't be present and should be
             // set manually
             if (!port) {
-                if (window.location.protocol.substring(0,4) == 'http') {            
-                    port = 80;
-                }
-                else if (window.location.protocol.substring(0,5) == 'https') {            
+                if (window.location.protocol.substring(0,5) == 'https') {
                     port = 443;
                 }
+                else if (window.location.protocol.substring(0,4) == 'http') {
+                    port = 80;
+                }
             }
 
             // If a token variable is passed in, set the parameter in a cookie.