Possible Duplicate:
Detect If Browser Tab Has Focus
I have a simple java applet that captures client's screen. With the help of a piece of javascript code, I am able to call the applet and capture the active screen picture.
But, even though it only captures active screen with a click on a button, users are likely to manipulate the process by switching to some other tab with ALT TAB while capture process. I want to make sure that capturing must be done only if page is loaded and page is focused.
So far, I found this piece of javascript code which doesn't seem to be working correctly. Sometimes it gets stuck at the focus even though the page is minimized.
<script language="javascript">
window.onpageshow = function(e) { console.log('pageshow'); };
window.onfocus = function(e) { console.log('focus'); };
</script>
So are there any suggestions to what I am trying to achieve or any other solutions.