469,325 Members | 1,613 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

Making icon in taskbar flash

eragon
431 256MB
hello good people. i have a chatroom on my website and i was looking for a script that would make the little icon for the browser flash when there is new activity, or make a popup, or something. is there a javascript code i can make that lets the browser know when there is activity. i use a div that is updated with AJAX to hold the content. when a new message is sent i would like to have something blink, a visual notification, and a little ding or some sound that would let people know somebody said something.

thanks
Nov 22 '07 #1
7 5273
acoder
16,027 Expert Mod 8TB
You can't make the icon flash, but you could play a sound (depending upon support and user preferences). Visual notification would have to be limited to within the browser, not outside.
Nov 23 '07 #2
eragon
431 256MB
thats interesting, because i used meebo and when i get a message the button for firefox flashes. maybe its just really hard. on my page is a div tag that is updated with ajax, i would like to know how to play a sound when a new line is added to the div. can you help me?
Nov 23 '07 #3
acoder
16,027 Expert Mod 8TB
There is one possibility: you could change the title repeatedly using setInterval.
Nov 25 '07 #4
eragon
431 256MB
my title already flashes between my sites name and the short url, so i can add another, like, New Message, that will join the cycle and let me know, but i am not ajax savvy and have absolutely no clue on earth how to detect more information in the box. maybe find a difference of scroll height? and how does it know when i view the messages? i could put a onClick in my text entry field... i dont know... thats why im asking for help. please?
Nov 25 '07 #5
acoder
16,027 Expert Mod 8TB
You know that it's updated when the Ajax object's readyState is 4.

What does your code look like? Can you post some of it?
Nov 26 '07 #6
eragon
431 256MB
soyatinly... (its a large script)

[html]
<?php session_start();
if(!isset($_SESSION['userid'])) { exit; } ?>
<html>
<head>
<title>Ajax Chat 3.1 (Room 1)</title>
<style type="text/css">
#content {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
<!--username styles goe here-->
</style>
<script type="text/javascript">
function moveToBottom()
{
var div = document.getElementById('chatwindow');
h = div.scrollHeight;
sh = div.scrollTop;
st = div.offsetHeight;
difference = h - sh;
alt = st + 50
if (difference > alt) {
} else {
div.scrollTop = h;
}
}

function forceToBottom()
{
var div = document.getElementById('chatwindow');
h = div.scrollHeight;
div.scrollTop = h;
}

var t
function timedCount()
{
t=setTimeout("moveToBottom()",200)
t=setTimeout("timedCount()",200)
}
</script>
</head>
<body>



<div id="content" style="overflow:hidden;">
<div id="chatwindow" style="overflow:auto; height:300px; border: 1px solid #CCCCCC;" height="300px"></div>
<input id="chatnick" type="hidden" value="<?php echo(''.$_SESSION['userid'].''); ?>">
Smilies and other options coming soon! &nbsp;<br>
<input id="chatmsg" type="text" size="60" maxlength="80" onkeyup="keyup(event.keyCode); timedCount();">
<input type="button" value="add" onClick="submit_msg(); timedCount();" style="cursor:pointer;border:1px solid gray;">
<input name="button" type="button" style="cursor:pointer;border:1px solid gray;" onClick="forceToBottom();" value="&dArr;">
</div>

</body>
</html>

<script type="text/javascript">

/* Settings you might want to define */
var waittime=10;

/* Internal Variables & Stuff */
chatmsg.focus()
document.getElementById("chatwindow").innerHTML = "<center><b><p><p>Loading...</b></center>";

var xmlhttp = false;
var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_read(url) {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("chatwindow").innerHTML = xmlhttp.responseText;

zeit = new Date();
ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
intUpdate = setTimeout("ajax_read('chat.txt?x=" + ms + "')", waittime)
}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}

/* Request for Writing the Message */
function ajax_write(url){
if(window.XMLHttpRequest){
xmlhttp2=new XMLHttpRequest();
if(xmlhttp2.overrideMimeType){
xmlhttp2.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp2) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

xmlhttp2.open('GET',url,true);
xmlhttp2.send(null);
}

/* Submit the Message */
function submit_msg(){
nick = document.getElementById("chatnick").value;
msg = document.getElementById("chatmsg").value;

if (nick == "") {
check = prompt("please enter username:");
if (check === null) return 0;
if (check == "") check = "anonymous";
document.getElementById("chatnick").value = check;
nick = check;
}

document.getElementById("chatmsg").value = "";
ajax_write("w.php?m=" + msg + "&n=" + nick);
}

/* Check if Enter is pressed */
function keyup(arg1) {
if (arg1 == 13) submit_msg();
}

/* Start the Requests! ;) */
var intUpdate = setTimeout("ajax_read('chat.txt')", waittime);

</script>
[/html]

and theres another page, see next post
Nov 28 '07 #7
eragon
431 256MB
contd.

[php]
<?php
session_start();
//$_SERVER['REQUEST_TIME'];
date_default_timezone_set('America/New_York');
/* author: chris at linuxuser.at
licence: GPLv2
*/

$fn = "chat.txt";
$maxlines = 180000;
$nick_length = 100;

/* Set this to a minimum wait time between posts (in sec) */
$waittime_sec = 0;

/* spam keywords */


/* IP's to block */
$blockip[] = "72.60.167.89";

/* spam, if message IS exactly that string */
$espam[] = "ajax";

/* Get Message & Nick from the Request and Escape them */
$msg = $_REQUEST["m"];
$msg = htmlspecialchars(stripslashes($msg));

$n = $_REQUEST["n"];
$n = htmlspecialchars(stripslashes($n));

if (strlen($n) >= $nick_length) {
$n = substr($n, 0, $nick_length);
} else {
for ($i=strlen($n); $i<$nick_length; $i++) $n .= "";
}

if ($waittime_sec > 0) {
$lastvisit = $_COOKIE["lachatlv"];
setcookie("lachatlv", time());

if ($lastvisit != "") {
$diff = time() - $lastvisit;
if ($diff < 5) { die(); }
}
}

if ($msg != "") {
if (strlen($msg) < 2) { die(); }
if (strlen($msg) > 3) {
/* Smilies are ok */
if (strtoupper($msg) == $msg) { die(); }
}
if (strlen($msg) > 150) { die(); }
if (strlen($msg) > 15) {
if (substr_count($msg, substr($msg, 6, 8)) > 1) { die(); }
}

foreach ($blockip as $a) {
if ($_SERVER["REMOTE_ADDR"] == $a) { die(); }
}

$mystring = strtoupper($msg);
foreach ($spam as $a) {
if (strpos($mystring, strtoupper($a)) === false) {
/* Everything Ok Here */
} else {
die();
}
}

foreach ($espam as $a) {
if (strtoupper($msg) == strtoupper($a)) { die(); }
}

$handle = fopen ($fn, 'r');
$chattext = fread($handle, filesize($fn)); fclose($handle);

$arr1 = explode("\n", $chattext);

if (count($arr1) > $maxlines) {
/* Pruning */
$arr1 = array_reverse($arr1);
for ($i=0; $i<$maxlines; $i++) { $arr2[$i] = $arr1[$i];
}
$arr2 = array_reverse($arr2);
} else {
$arr2 = $arr1;
}

$chattext = implode("\n", $arr2);

if (substr_count($chattext, $msg) > 2) { die(); }
//Now we add the time:
$today = date("g:i A");

$out = $chattext . "<font class=\"".$_SESSION['userid']."\">[".$today."] " . $n . ":</font> " . $msg . "<br>\n";
$out = str_replace("\'", "'", $out);
$out = str_replace("\\\"", "\"", $out);

// lovely smilies :)
$raw = array(
":)",
":(",
";)",
":o",
":@",
"-.-",
":D",
">.>",
":,("
);
$happy = array(
"<img src=\"../images/smile/1.gif\" />",
"<img src=\"../images/smile/2.gif\" />",
"<img src=\"../images/smile/5.gif\" />",
"<img src=\"../images/smile/3.gif\" />",
"<img src=\"../images/smile/6.gif\" />",
"<img src=\"../images/smile/8.gif\" />",
"<img src=\"../images/smile/4.gif\" />",
"<img src=\"../images/smile/9.gif\" />",
"<img src=\"../images/smile/7.gif\" />"
);
$outs = str_replace($raw, $happy, $out);

$handle = fopen ($fn, 'w'); fwrite ($handle, $outs); fclose($handle);
}
?>
[/php]
yay php. this one is the trimmer that cleans up the posts. if you want i would be more than happy if you cleaned it up, also, if you made a way to have multiple rooms in onw by setting a get paramatre in cht.php so it writes to a different text file. also, how do i get ajax to stop refreshing my smilies every second, it gets annoying... thanks!
Nov 28 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Morten Bendsen | last post: by
reply views Thread by Huw Lloyd | last post: by
3 posts views Thread by jm | last post: by
2 posts views Thread by Brian | last post: by
reply views Thread by Jean Bredeche | last post: by
reply views Thread by Richard | last post: by
2 posts views Thread by flaper87 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.