新的聊天窗口
New Chat window
我有一个聊天(没有任何设计到现在)
<div id="chatHtml">
<input type="text" id="input-text-chat" placeholder="Enter Text Chat">
<div id="chat-container">
<div id=chatOutput class="chat-output"></div>
</div>
</div>
现在我有一个按钮,它调用一个javascript函数来打开一个新窗口
<button type="button" v-on:click="openChat">open chat</button>
openChat: function() {
win = top.consoleRef = window.open('', 'myconsole',
'width=350,height=250' +
',menubar=0' +
',toolbar=1' +
',status=0' +
',scrollbars=1' +
',resizable=1')
chat = document.getElementById("chatHtml").innerHTML;
win.document.write(chat);
}
最后是聊天正在工作的代码
document.getElementById('input-text-chat').onkeyup = function(e) {
if (e.keyCode != 13) return;
// removing trailing/leading whitespace
// this.value = this.value.replace(/^'s+|'s+$/g, '');
if (!this.value.length) return
connection.send(this.value);
console.log(connection.send);
console.log(this.value);
appendDIV(this.value);
this.value = '';
};
var chatContainer = document.querySelector('.chat-output');
function appendDIV(event) {
var div = document.createElement('div');
div.innerHTML = event.data || event;
chatContainer.insertBefore(div, chatContainer.firstChild);
div.tabIndex = 0;
div.focus();
document.getElementById('input-text-chat').focus();
win.document.write(chatContainer.innerHTML);
}
我的问题:
聊天不工作在新的窗口,但在"索引窗口"它是。我完全新的javascript和我不知道什么问题。我想是因为身份证之类的原因。有人能帮我用一下新窗口里的聊天功能吗?谢谢:)
你的新页面的输入还没有事件,所以绑定它的事件
就加上这个
openChat: function(){
win =top.consoleRef=window.open('','myconsole',
'width=350,height=250'
+',menubar=0'
+',toolbar=1'
+',status=0'
+',scrollbars=1'
+',resizable=1')
chat = document.getElementById("chatHtml").innerHTML;
win.document.write(chat);
win.document.getElementById('input-text-chat').onkeyup = function(e) {
if (e.keyCode != 13) return;
// removing trailing/leading whitespace
// this.value = this.value.replace(/^'s+|'s+$/g, '');
if (!this.value.length) return
connection.send(this.value);
console.log(connection.send);
console.log(this.value);
appendDIV(this.value);
this.value = '';
};
}
后win.document.write(chatContainer.innerHTML);
最好在事件后面加上一个名字来减少代码
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 防止Iframe窗体在新窗口中打开
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 调整窗口大小时,可拖动的对象会出现在容器外部
- Javascript排序的图像弹出窗口..可以't单独弹出
- 窗口大小html css
- Ajax聊天消息重复而不仅仅是更新
- 弹出窗口出现,然后退出
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- 在聊天窗口中检测链接单击事件
- 通过jquery或javascript中的cookie记住聊天窗口状态
- 当我玩swf游戏时,如何阻止聊天窗口弹出
- 当用户导航到不同的页面时,facebook如何保持聊天窗口打开
- Javascript的方式与StropheJS干净的退出,当你关闭聊天窗口
- 单击X按钮关闭窗口聊天框时的事件本地存储
- 新的聊天窗口
- 跟踪聊天窗口事件,我如何让这两个脚本一起工作
- ASP.Net聊天应用程序javascript弹出窗口
- 如何在GMail中实现聊天窗口的弹出功能
- 哪些JavaScript库将处理弹出窗口(例如Meebo或Gmail聊天窗口)