4 noVNC Example: Automatically connect on page load.
5 Copyright (C) 2011 Joel Martin
6 Licensed under LGPL-3 (see LICENSE.txt)
8 Connect parameters are provided in query string:
9 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
13 <meta http-equiv=
"X-UA-Compatible" content=
"chrome=1">
14 <link rel=
"stylesheet" href=
"include/base.css" title=
"plain">
16 <script type='text/javascript'
17 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
19 <script src=
"include/vnc.js"></script>
22 <body style=
"margin: 0px;">
23 <div id=
"noVNC_screen">
24 <div id=
"noVNC_status_bar" class=
"noVNC_status_bar" style=
"margin-top: 0px;">
25 <table border=
0 width=
"100%"><tr>
26 <td><div id=
"noVNC_status">Loading
</div></td>
27 <td width=
"1%"><div id=
"noVNC_buttons">
28 <input type=button
value=
"Send CtrlAltDel"
29 id=
"sendCtrlAltDelButton">
33 <canvas id=
"noVNC_canvas" width=
"640px" height=
"20px">
39 /*jslint white: false */
40 /*global window, $, Util, RFB, */
45 function passwordRequired(rfb) {
47 msg = '
<form onsubmit=
"return setPassword();"';
48 msg += '
style=
"margin-bottom: 0px">';
49 msg += 'Password Required: ';
50 msg += '
<input type=password size=
10 id=
"password_input" class=
"noVNC_status">';
52 $D('noVNC_status_bar').setAttribute(
"class",
"noVNC_status_warn");
53 $D('noVNC_status').innerHTML = msg;
55 function setPassword() {
56 rfb.sendPassword($D('password_input').value);
59 function sendCtrlAltDel() {
63 function updateState(rfb, state, oldstate, msg) {
64 var s, sb, cad, level;
65 s = $D('noVNC_status');
66 sb = $D('noVNC_status_bar');
67 cad = $D('sendCtrlAltDelButton');
69 case 'failed': level =
"error"; break;
70 case 'fatal': level =
"error"; break;
71 case 'normal': level =
"normal"; break;
72 case 'disconnected': level =
"normal"; break;
73 case 'loaded': level =
"normal"; break;
74 default: level =
"warn"; break;
77 if (state ===
"normal") { cad.disabled = false; }
78 else { cad.disabled = true; }
80 if (typeof(msg) !== 'undefined') {
81 sb.setAttribute(
"class",
"noVNC_status_" + level);
86 window.onload = function () {
87 var host, port, password, path, token;
89 $D('sendCtrlAltDelButton').style.display =
"inline";
90 $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
92 document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
93 // By default, use the host and port of server that served this file
94 host = WebUtil.getQueryVar('host', window.location.hostname);
95 port = WebUtil.getQueryVar('port', window.location.port);
97 // If a token variable is passed in, set the parameter in a cookie.
98 // This is used by nova-novncproxy.
99 token = WebUtil.getQueryVar('token', null);
101 WebUtil.createCookie('token', token,
1)
104 password = WebUtil.getQueryVar('password', '');
105 path = WebUtil.getQueryVar('path', 'websockify');
107 if ((!host) || (!port)) {
108 updateState('failed',
109 "Must specify host and port in URL");
113 rfb = new RFB({'target': $D('noVNC_canvas'),
114 'encrypt': WebUtil.getQueryVar('encrypt',
115 (window.location.protocol ===
"https:")),
116 'repeaterID': WebUtil.getQueryVar('repeaterID', ''),
117 'true_color': WebUtil.getQueryVar('true_color', true),
118 'local_cursor': WebUtil.getQueryVar('cursor', true),
119 'shared': WebUtil.getQueryVar('shared', true),
120 'view_only': WebUtil.getQueryVar('view_only', false),
121 'updateState': updateState,
122 'onPasswordRequired': passwordRequired});
123 rfb.connect(host, port, password, path);