Javascript 如何检测用户单击了我的html页面所在的页面选项卡?
我正在开发一个网络聊天,我需要在对话发生变化时引发一个事件,这样页面标题就会发生变化,这样一个用户就可以知道另一个用户写了任何东西 所以我尝试了代码:Javascript 如何检测用户单击了我的html页面所在的页面选项卡?,javascript,events,focus,window,document,Javascript,Events,Focus,Window,Document,我正在开发一个网络聊天,我需要在对话发生变化时引发一个事件,这样页面标题就会发生变化,这样一个用户就可以知道另一个用户写了任何东西 所以我尝试了代码: addEvent(window,'focus',function(){ alert(1); } ); 及 addEvent(文档,'focus',函数(){alert(2);}) 但它不起作用 我需要引发事件,即使用户没有单击网页上的 对于该事件,我有以下解决方案: <body onclick="showClickedElement(th
addEvent(window,'focus',function(){ alert(1); } );
及
addEvent(文档,'focus',函数(){alert(2);})
但它不起作用
我需要引发事件,即使用户没有单击网页上的
对于该事件,我有以下解决方案:
<body onclick="showClickedElement(this);" >
有什么解决办法吗
提前感谢。摘自:
如果addEvent无法使用,您可能需要尝试jQuery(请参阅)
我发现这段代码适用于IE6、7、8和firefox,不需要Jquery
function onBlur() {
document.body.className = 'blurred';
});
函数onFocus(){
document.body.className='focused';
};
如果(/@cc_on!@/false){//检查Internet Explorer
document.onfocusin=onFocus;
document.onfocusout=onBlur;
}否则{
window.onfocus=onfocus;
window.onblur=onblur;
}
你好。谢谢你的密码。在firefox中工作,但在IE8中不工作。
$(window).blur(function(e) {
// Do Blur Actions Here
});
$(window).focus(function(e) {
// Do Focus Actions Here
});
function onBlur() {
document.body.className = 'blurred';