diff --git a/include/staff/ticket-view.inc.php b/include/staff/ticket-view.inc.php
index c39d1bcee555bff254f6b73017b7c3db9f2e48a5..d19e5e5a9d34eb9679b37003e0e3c99da6d5dcda 100644
--- a/include/staff/ticket-view.inc.php
+++ b/include/staff/ticket-view.inc.php
@@ -993,9 +993,16 @@ $(function() {
 <?php
     // Set the lock if one exists
     if ($lock) { ?>
+!function() {
+  var setLock = setInterval(function() {
+    if (typeof(window.autoLock) === 'undefined')
+      return;
+    clearInterval(setLock);
     autoLock.setLock({
       id:<?php echo $lock->getId(); ?>,
       time: <?php echo $cfg->getLockTime(); ?>}, 'acquire');
+  }, 50);
+}();
 <?php } ?>
 });
 </script>