我有一个使用textarea而不是文本的聊天,原因很明显.这就是每次成员点击ENTER时他们得到一个新行而不是发送消息的原因.我想改变它,所以每次他们点击ENTER =要提交的消息然后光标返回textarea以便他们下一个消息输入.我尝试过在这个网站上找到的不同代码,大多数都没有用,而那些似乎做某事的人只是刷新页面,我得到了一个空白页面.
我的代码:
<form name="message" action="">
<textarea name="usermsg" autocomplete="off" type="text" id="usermsg" rows="4" cols="30" style="width: 450px; margin-left: 25px;">
</textarea>
<br/>
<p style="margin-left: 420px;"><input name="submitmsg" type="submit" id="submitmsg" value="Send" /></p>
</form>
Run Code Online (Sandbox Code Playgroud)
非常感谢您的宝贵时间.
我正在尝试在聊天中添加"用户输入"功能; 用PHP + MySQL/Ajax编写的聊天.
它应该如何工作:
- 当我的聊天伙伴X开始输入时,我在聊天框中看到:"X正在输入"
- 当我(名字Y)正在打字时,他在聊天框中看到:"Y正在打字"(就像Yahoo Messenger一样).
到目前为止我尝试过的代码:
<script type="text/javascript" language="javascript">
var timer = 0;
function reduceTimer() {
timer = timer - 1;
isTyping(true);
}
function isTyping(val) {
if (val == 'true') {
document.getElementById('typing_on').innerHTML = "User is typing...";
} else {
if (timer <= 0) {
document.getElementById('typing_on').innerHTML = "No one is typing -blank space.";
} else {
setTimeout("reduceTimer();", 500);
}
}
}
</script>
<label>
<textarea onkeypress="isTyping('true'); timer=5;" onkeyup="isTyping('false')" name="textarea" id="textarea" cols="45" rows="5"></textarea>
</label>
<div id="typing_on">No one is …
Run Code Online (Sandbox Code Playgroud) 我创建了一个小部件.实际上我把信息放在一个php文件中然后我把这个文件的Iframe代码提供给我的成员.
考虑到站点A是成员的站点,站点B是我的站点.
站点A显示IFRAME:
<iframe src="http://siteB.com/try.php" height="240px" width="286px"></iframe>
Run Code Online (Sandbox Code Playgroud)
单击此IFRAME时,会打开一个新的弹出窗口,因为此代码:
<a href="#" onClick="return mbetter('http://siteB.com/chat/new_chat.php?reader=<?php echo $id; ?>')"><?php echo $status_img; ?></a>
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
现在问题是这个弹出窗口也有一个链接.如何在IFRAME之外打开此链接,更具体地说,将它们带到我的网站B站点.此链接在iframe内打开,不能以这种方式使用.
最后一个链接是:
<a onclick="return targetopener(this,true)" target="_top" href="http://siteB.com/services.php">
Run Code Online (Sandbox Code Playgroud)
它在我的网站上完美运行,但在iframe中却无法运行.我知道我用这个iframe让自己变得有点复杂,但我对我的知识进行了改进.我打开了新的解决方案,如果此链接无法在Iframe外打开.先感谢您!