Dear sir,
I have created some windows for the users to type the message. If one user wants to send the message to no of users, he will open different windows for different users. But if i type the message in one window sometimes the message doesnt appears in that window it appears in the another window.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Regalmail-Beta Chat</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
#chatContents{height:300px; width:510px;}
</style>
<script type="text/javascript">
function resetForm()
{
document.getElementById("message").value = "";
document.getElementById("message").focus();
}
function focusForm()
{
document.getElementById("message").focus();
}
function focustext()
{
var name=window.name;
<?
$sql2 = "SELECT chat_tmp_usr_id1 FROM chat_temp_table";
$res2 = mysql_query($sql2);
if(mysql_num_rows($res2))
{
while($row2 = mysql_fetch_array($res2))
{?>
var id25='<?echo "".$row2['chat_tmp_usr_id1']?>';
if(name==id25)
{
document.getElementById("message1").value=name;
}
<?}}?>
document.getElementById("statusmessage").style.display="inline";
}
function losttext()
{
document.getElementById("statusmessage").style.display="none";
}
var cWindow;
var cDocument;
var id11;
function chat_init()
{
var chatContents = document.getElementById("chatContents");
if(chatContents.contentWindow)
cWindow = chatContents.contentWindow;
if(cWindow.document)
cDocument=cWindow.document;
}
function insertMessages(content)
{
//place the new messages in a div
var newDiv = cDocument.createElement("DIV");
newDiv.innerHTML = content;
//append the messages to the contents
cDocument.getElementById("contents").appendChild(newDiv);
//scroll the chatContents area to the bottom
cWindow.scrollTo(0,cDocument.getElementById("contents").offsetHeight);
}
</script>
</head>
<style>
body
{
background-color: #EBF3FB;
color: #000000;
}
</style>
<script type="text/javascript">
if(parent.insertMessages && document.getElementById("contents"))
parent.insertMessages(document.getElementById("contents").innerHTML);
</script>
<?
$sql1 = "SELECT chat_user_id,chat_user_id1,chat_user_name,Message FROM chat_table WHERE chat_user_id=".$SESSION['Chat3_UserID']." and chat_flag='".$flag10."'";
$res1 = mysql_query($sql1);
if(mysql_num_rows($res1))
{
echo '<div id="contents">';
while($row1 = mysql_fetch_array($res1))
{
if($row1['chat_user_id']==$SESSION['Chat3_UserID'])
echo '<div class="ylayout-active-content" style="font-size:14px;font-face:arial;"><strong>'.htmlspecialchars($row1['chat_user_name']).':</strong>'.htmlspecialchars($row1['Message']).'</div>';
}
echo '</div>';
}
?>
<body>
<iframe id="chatContents" name="chatContents" src="contents.html" onload="javascript:chat_init();"></iframe><br>
<div style="display:none;color:red;height:1px;" id="statusmessage"><?echo "".$_SESSION['Chat1_UserName']?> is typing</div><br><br>
<form target="post" method="post" action="post.php">
<input type="text" onkeydown="javascript:focustext();" onkeyup="javascript:losttext();" name="message" id="message" style="width: 460px;height: 40px;" />
<input type=hidden name="message1" id="message1" value="" />
<input type="submit" value="Send" class="submit" style="width: 55px;height: 47px;" />
</form>
<iframe id="post" name="post" src="post.php" style="width: 0px; height: 0px; border: 0px;"></iframe>
<iframe id="thread" name="thread" src="thread.php" style="width: 0px; height: 0px; border: 0px;"></iframe>
</body>
</html>
This code gets called for every window opened. I wanted to add the message in the same window where i am typing the message.
mandar :😕