How to: Enable Ajax Chat audio alerts by default and have a flashing title bar when chat window is not in focus

Submitted 9/6/2010 by Josh Anderson

I like how FB has the audio alert for chat on by default. I also like how the title bar "flashes" when I have a new message and the window is not in focus or minimized.

 

Paste the following scripts at the bottom of your MessengerWindow.aspx:

 

<script type="text/javascript">

/// Added this to set audio alerts by default - add just this first script

/// for the chatwindow.aspx to have audio alerts on by default.

document.getElementById('imgAlertButton').onclick();

SetAlert((document.getElementById('hidAlertButtonState').value = (document.getElementById('hidAlertButtonState').value == 'button' ? 'buttondown' : 'button')) == 'buttondown');

document.getElementById('hidAlertButtonState').value == 'button' ? this.className = 'buttonover' : this.className = 'buttondown';

document.getElementById('imgAlertButton').className = 'buttondown';

</script>

 

<script type="text/javascript">

var windowsFocused = new Boolean(true);

 

function onBlur() {

windowsFocused = false;

};

function onFocus() {

windowsFocused = true;

document.title = "A/V Chat - <%= this.TargetUsername %>";

};

if (/*@cc_on!@*/false) { // check for Internet Explorer

document.onfocusin = onFocus;

document.onfocusout = onBlur;

} else {

window.onfocus = onFocus;

window.onblur = onBlur;

}

 

var divMessagesCount = document.getElementById('messages').innerHTML.length;

 

function divpoll() {

if (document.getElementById('messages').innerHTML.length > divMessagesCount) {titlebar(0); }

divMessagesCount = document.getElementById('messages').innerHTML.length;

//alert(windowsFocused);

}

 

setInterval(function () { divpoll(); }, 2000);

function titlebar(val) {

if (windowsFocused) { return; }

var msg = "New Message from <%= this.TargetUsername %>!";

var speed = 1000;

var pos = val;

var msg1 = msg;

var msg2 = "A/V Chat - <%= this.TargetUsername %>";

if (pos == 0) {

masg = msg1;

pos = 1;

}

else if (pos == 1) {

masg = msg2;

pos = 0;

}

document.title = masg;

timer = window.setTimeout("titlebar(" + pos + ")", speed);

}

</script>

Comments

Chris Giles: 

Can this be applied to the chat window also???

4/26/2012 12:13:09 AM +03:00