@@ -60,6 +60,7 @@
             getUserMediaSupport(function (x) { userMediaSupport = x; })
             var webrtcconfiguration = '{{{webrtconfig}}}';
             if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
+            var windowFocus = true;
 
             // File transfer state
             var fileUploads = [];
@@ -73,6 +74,10 @@
             // Setup web notifications
             if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
 
+            // Track window focus
+            window.addEventListener('focus', function (event) { windowFocus = true; }, false);
+            window.addEventListener('blur', function (event) { windowFocus = false; }, false);
+
             // Listen to drag & drop events
             document.addEventListener('dragover', haltEvent, false);
             document.addEventListener('dragleave', haltEvent, false);
@@ -150,7 +155,7 @@
             // Display a control message
             function displayControl(msg) {
                 QA('xmsg', '
');
-                Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
+                Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;//Q('xmsg').scrollHeight;
             }
 
             function displayLocalVideo(active) { QV('localVideo', active); adjustVideoWindows(); }
@@ -163,12 +168,13 @@
 
             // Display a message from the remote user
             function displayRemote(msg) {
+                console.log(document.activeElement);
                 QA('xmsg', '
');
-                Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
+                Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
 
                 // If web notifications are granted, use it.
                 if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
-                if (Notification && (Notification.permission == 'granted')) {
+                if (Notification && (windowFocus == false) && (Notification.permission == 'granted')) {
                     if (notification != null) { notification.close(); notification = null; }
                     if (args.title) {
                         notification = new Notification("MeshMessenger" + ' - ' + args.title, { body: msg });
@@ -186,7 +192,7 @@
                 if (outtext.length > 0) {
                     Q('xouttext').value = '';
                     QA('xmsg', '
' + EscapeHtml(outtext) + '
');
-                    Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
+                    Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
                     send({ action: 'chat', msg: outtext });
                 }
             }
@@ -420,7 +426,7 @@
                 file.id = Math.random();
                 fileUploads.push(file);
                 QA('xmsg', '
');
-                Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
+                Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
                 send({ action: 'file', size: file.size, id: file.id, type: file.type, name: file.name });
                 if (currentFileUpload == null) continueFileUpload();
             }
@@ -429,7 +435,7 @@
                 if (state != 2) return;
                 fileDownloads[file.id] = file;
                 QA('xmsg', '
');
-                Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
+                Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
             }
 
             // Change the file icon and progress