【发布时间】:2011-02-01 18:17:43
【问题描述】:
大家好,我正在开发一个聊天应用程序...我有多个聊天窗口...我想知道哪个窗口包含新消息...我有以下代码..
function getCount()
{
$.ajax({
type: "POST",
url: baseUrl + '/Chat/count',
data: "chat_id=" + document.ajax.chat_id.value,
success: function(msg){
if(msg == 'new1') {
self.focus();
//window.focus();
}
}
});
}
如果一个接线员同时参加两个聊天......
例如,网址就像 http://localhost/nisanth/admin/Chat/index/chatId/15 http://localhost/nisanth/admin/Chat/index/chatId/16
http://localhost/nisanth/user/Chat/index/chatId/15 http://localhost/nisanth/user/Chat/index/chatId/16
如果user 16 输入消息我需要关注
http://localhost/nisanth/admin/Chat/index/chatId/16
这段代码在 IE 下可以正常工作,但在 Firefox 中不行...请给我一个解决方案...上面的代码在同一个 html 中
【问题讨论】:
-
我看不出它在 IE 中是如何工作的;
self在引用的代码中未定义。如果它在其他地方定义,最好表明这一点,因为了解它的含义很重要。 -
“...我想知道哪个窗口包含新消息...”与
focus没有达到您的预期有何关系? (另外,你能解释一下你的意思吗?) -
@Nisanth:
window可能是,但又不是self,除非您在其他地方定义它。self不是内置对象。这是很多人在闭包中使用的名称,当他们想要从闭包中引用this值时,他们将其作为回调/事件处理程序传递,但要做到这一点,您必须实际定义它(例如,var self= this;)。 -
self.focus() 在 IE8 中工作
-
好吧,@Nisanth;这与在 Firefox 中什么可以工作的问题无关,因为在 Firefox 中它是在用户控制之下的。
标签: javascript jquery jquery-plugins