Index: /package_branches/invirt-web/cherrypy/code/static/ajaxterm/ajaxterm.js
===================================================================
--- /package_branches/invirt-web/cherrypy/code/static/ajaxterm/ajaxterm.js	(revision 2452)
+++ /package_branches/invirt-web/cherrypy/code/static/ajaxterm/ajaxterm.js	(revision 2453)
@@ -254,6 +254,13 @@
 			opt_paste.attachEvent("onclick", do_paste);
 		}
-		$('term').onkeypress=keypress;
-		$('term').onkeydown=keydown;
+                // If tabIndex works, only grab keyboard events when terminal is focused
+                // Otherwise, grab from whole document (e.g. in Safari).
+                var focus_element = document;
+                if(typeof $('term').tabIndex != "undefined") {
+                    focus_element = $('term');
+                    focus_element.focus();
+                }
+		focus_element.onkeypress=keypress;
+		focus_element.onkeydown=keydown;
 		force=true;
 		timeout=window.setTimeout(update,100);
Index: /package_branches/invirt-web/cherrypy/code/templates/terminal.mako
===================================================================
--- /package_branches/invirt-web/cherrypy/code/templates/terminal.mako	(revision 2452)
+++ /package_branches/invirt-web/cherrypy/code/templates/terminal.mako	(revision 2453)
@@ -22,5 +22,4 @@
 window.onload=function() {
 	t=ajaxterm.Terminal("term", ${machine.machine_id});
-        $('term').focus();
 }
 </script>
