Forum Moderators: open

Message Too Old, No Replies

how to track if the browser is active/inactive?

i'm puzzled by onfocus/onblur

         

Xuefer

11:45 am on Jan 27, 2003 (gmt 0)

10+ Year Member



i tried to use <body onfocus='...' onblur='...'>
bu i was failed

is there anyways to check if the browser is active?
or even the window is active

HocusPocus

1:27 pm on Jan 27, 2003 (gmt 0)

10+ Year Member



How about checking if there's mouse movement or keyboard activity? sumthing like

function doStuff()
{
...

}
document.onmousemove = doStuff;
document.onkeypress = doStuff;

joshie76

1:31 pm on Jan 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've never heard of any way of directly ascertaining this but you could try something along these lines.

Usually the window would have focus when a page loads (unless the load happened via some scripting) so you could just set a variable (isactive) to false in the onblur event and true in the onfocus event... (any child elements [input, iframe etc] of the body would need to set the variable to true when they steal focus)

But why on earth do you need to know this?

joshie76

1:39 pm on Jan 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, having just played around with it I'm not sure that the onblur event fires when you move to another application...

lorax

3:08 pm on Jan 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean the window object within the browser versus the navigation/controls of the browser client?

Xuefer

5:08 pm on Jan 27, 2003 (gmt 0)

10+ Year Member



to joshie76:
i do wanna check it for my chatroom, when it's active, higlihght will not beep, if it's inactive, highlight will generate a beep

to HocusPocus: it maybe good for active, but how about inactive?

to lorax: "move from/to another applications"

lorax

9:53 pm on Jan 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> another applications

Then it'll depend upon the language your using for development and the OS you're working with. Each programming language ties into the OS through a set of APIs so you'll need to learn what those APIs are, the command sets they offer, and the syntax of the development language you're using to work with them.

Xuefer

4:23 am on Jan 28, 2003 (gmt 0)

10+ Year Member



to lorax: it's web/html :) not c/c++/vb

however, i don't care if it's IE specified, using ie existing activex(such as the browser object) is also acceptable

joshie76

1:26 pm on Jan 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i do wanna check it for my chatroom, when it's active, higlihght will not beep, if it's inactive, highlight will generate a beep

Seems like a good usage (providing you can turn it off ;)), however, I'm afraid my bet is that it can't be done.

You might want to look into activeElement and various other IE properties at MSDN.

Best of luck and if you nail it be sure to let us know.

Josh

lorax

1:37 pm on Jan 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sorry Xuefer,
Misunderstood what you meant by 'application'. In Javascript, the Window object is the top most object. It has an onFocus event handler which should do what you're looking for.

Gregg