summaryrefslogtreecommitdiff
path: root/vnc_lite.html
diff options
context:
space:
mode:
authorSamuel Mannehed <samuel@cendio.se>2018-08-16 11:23:11 +0200
committerSamuel Mannehed <samuel@cendio.se>2018-08-28 10:41:56 +0200
commit6517c498b9c93e805ead992cc4e5bafa18193fb3 (patch)
tree4abe1678ae82f361c4af44aa24d41e9a3c981d35 /vnc_lite.html
parent51f9f0098d306bbc67cc8e02ae547921b6f6585c (diff)
downloadnovnc-6517c498b9c93e805ead992cc4e5bafa18193fb3.tar.gz
Remove support for the fragment and WebUtil dep
The only remaining use we had of WebUtil was getConfigVar(). Let's get rid of that dependency and use our own, query-string-only and richly commented version of that function. It's easier for people to get an overview of vnc_lite if it's all in one file. This commit removes support for the fragment, parameters can only be passed using the query string from now on.
Diffstat (limited to 'vnc_lite.html')
-rw-r--r--vnc_lite.html39
1 files changed, 28 insertions, 11 deletions
diff --git a/vnc_lite.html b/vnc_lite.html
index fcb3e7c..828c5c8 100644
--- a/vnc_lite.html
+++ b/vnc_lite.html
@@ -14,8 +14,6 @@
Connect parameters are provided in query string:
http://example.com/?host=HOST&port=PORT&scale=true
- or the fragment:
- http://example.com/#host=HOST&port=PORT&scale=true
-->
<title>noVNC</title>
@@ -82,8 +80,6 @@
<!-- actual script modules -->
<script type="module" crossorigin="anonymous">
- // WebUtil contains helper functions for browser features
- import * as WebUtil from './app/webutil.js';
// RFB holds the API to connect and communicate with a VNC server
import RFB from './core/rfb.js';
@@ -147,14 +143,35 @@
}
}
+ // This function extracts the value of one variable from the
+ // query string. If the variable isn't defined in the URL
+ // it returns the default value instead.
+ function readQueryVariable(name, defaultValue) {
+ // A URL with a query parameter can look like this:
+ // https://www.example.com?myqueryparam=myvalue
+ //
+ // Note that we use location.href instead of location.search
+ // because Firefox < 53 has a bug w.r.t location.search
+ const re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
+ match = document.location.href.match(re);
+ if (typeof defaultValue === 'undefined') { defaultValue = null; }
+
+ if (match) {
+ // We have to decode the URL since want the cleartext value
+ return decodeURIComponent(match[1]);
+ }
+
+ return defaultValue;
+ }
+
document.getElementById('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
- // Read parameters specified in the URL (query string or fragment)
+ // Read parameters specified in the URL query string
// By default, use the host and port of server that served this file
- var host = WebUtil.getConfigVar('host', window.location.hostname);
- var port = WebUtil.getConfigVar('port', window.location.port);
- var password = WebUtil.getConfigVar('password', '');
- var path = WebUtil.getConfigVar('path', 'websockify');
+ var host = readQueryVariable('host', window.location.hostname);
+ var port = readQueryVariable('port', window.location.port);
+ var password = readQueryVariable('password', '');
+ var path = readQueryVariable('path', 'websockify');
// | | | | | |
// | | | Connect | | |
@@ -187,8 +204,8 @@
rfb.addEventListener("desktopname", updateDesktopName);
// Set parameters that can be changed on an active connection
- rfb.viewOnly = WebUtil.getConfigVar('view_only', false);
- rfb.scaleViewport = WebUtil.getConfigVar('scale', false);
+ rfb.viewOnly = readQueryVariable('view_only', false);
+ rfb.scaleViewport = readQueryVariable('scale', false);
})();
</script>
</head>