2 noVNC Example: Automatically connect on page load.
4 Connect parameters are provided in query string:
5 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
9 <title>VNC Client
</title>
10 <link rel=
"stylesheet" href=
"include/plain.css">
12 <script type='text/javascript'
13 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
15 <script src=
"include/vnc.js"></script>
18 <body style=
"margin: 0px;">
20 <div id=
"VNC_status_bar" class=
"VNC_status_bar" style=
"margin-top: 0px;">
21 <table border=
0 width=
100%
><tr>
22 <td><div id=
"VNC_status">Loading
</div></td>
23 <td width=
10%
><div id=
"VNC_buttons">
24 <input type=button
value=
"Send CtrlAltDel"
25 id=
"sendCtrlAltDelButton"
26 onclick=
"sendCtrlAltDel();"></div></td>
29 <canvas id=
"VNC_canvas" width=
"640px" height=
"20px">
36 function setPassword() {
37 RFB.sendPassword($('password_input').value);
40 function sendCtrlAltDel() {
43 function updateState(state, msg) {
44 var s, sb, klass, html;
46 sb = $('VNC_status_bar');
47 cad = $('sendCtrlAltDelButton');
51 klass =
"VNC_status_error";
54 klass =
"VNC_status_normal";
58 klass =
"VNC_status_normal";
61 msg = '
<form onsubmit=
"return setPassword();"';
62 msg += '
style=
"margin-bottom: 0px">';
63 msg += 'Password Required: ';
64 msg += '
<input type=password size=
10 id=
"password_input" class=
"VNC_status">';
68 klass =
"VNC_status_warn";
71 if (state ===
"normal") { cad.disabled = false; }
72 else { cad.disabled = true; }
74 if (typeof(msg) !== 'undefined') {
75 sb.setAttribute(
"class", klass);
80 window.onload = function () {
81 var host, port, password, encrypt;
83 url = document.location.href;
84 host = (url.match(/host=([A-Za-z0-
9.\-]*)/) || ['',''])[
1];
85 port = (url.match(/port=([
0-
9]*)/) || ['',''])[
1];
86 password = (url.match(/password=([^&#]*)/) || ['',''])[
1];
87 encrypt = (url.match(/encrypt=([A-Za-z0-
9]*)/) || ['',
1])[
1];
88 true_color = (url.match(/true_color=([A-Za-z0-
9]*)/) || ['',
1])[
1];
89 if ((!host) || (!port)) {
91 "Must specify host and port in URL");
95 RFB.setUpdateState(updateState);
97 RFB.connect(host, port, password, encrypt, true_color);