[英]javascript: events outside of a window
Is it possible to get a mouse event which is fired outside of a browser window? 是否有可能在浏览器窗口之外触发鼠标事件? Or is it possible to check if the mouse is pressed when the mouse is moved over a window? 还是可以检查在窗口上移动鼠标时是否按下了鼠标?
This is not possible, but from this sentence here - 这是不可能的,但是从这句话开始-
Or is it possible to check if the mouse is pressed when the mouse is moved over a window 或者可以在将鼠标移到窗口上时检查是否按下了鼠标
You can check when the page is being focused, so when someone switches back to your page tab. 您可以检查页面何时聚焦,以便何时有人切换回页面选项卡。
window.onfocus = function() {
console.log('focus');
alert('focus'); // See note
};
Note - If you use
alert
in theonfocus
event thealert
will popup multiple times. 注意-如果在onfocus
事件中使用alert
,alert
将多次弹出。 This only happens withalert
and must be a bug somewhere, maybe someone can shed some light on it. 这仅在alert
时发生,并且一定是某个地方的错误,也许有人可以对此有所了解。
It is possible to see if the mouse is in the window or not. 可以查看鼠标是否在窗口中。 You could do this with a setInterval
that checks every 300 ms or so to see if the mouse is in the window. 您可以使用setInterval
进行此操作,该setInterval
每300毫秒左右检查一次,以查看鼠标是否在窗口中。
You could also use mouseout
and mouseover
events, assuming you can include jQuery. 您还可以使用mouseout
和mouseover
事件,假设您可以包含jQuery。
$(document).mouseout(function(){
alert("Mouse not in window");
});
$(document).mouseover(function(){
alert("Mouse in window");
});
Picking up click events and other things outside the browser are not possible. 无法在浏览器之外拾取点击事件和其他内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.