问题
Can I check if host page for a JavaScript is active by the browser's tab in IE7/FF/Opera?
Checking other tabs than the page where this JS runs would probably be a security risk though..
My other option is a method I remember by prototype to check if the mouse cursor is active, but it's not that accurate.
回答1:
You can attach the onBlur and onFocus events to the window; that will tell you if you have focus or not. I have tested this and it works. You cannot check another page, but you can definitely check your own.
来源:https://stackoverflow.com/questions/512087/check-browser-tabs-by-javascript