Reputation:
I have a div that toggles in and out of display when you click on another div. How could I modify my code so that when the user minimizes the whole browser window it automatically toggles, hiding the div from view so when the user un-minimizes window the div is no longer visible.
Upvotes: 2
Views: 8424
Reputation: 5191
Minimizing the window (or switching to another application) should fire the window.onblur event. Activating the window should fire window.onfocus
Implementation details may differ slightly between browsers but there seems to be no better way in default javascript (may be you can use some flash object if flash can detect minimizing/maximizing of the window to fire necessary events, but I'm not familiar with flash)
Upvotes: 3
Reputation: 103397
In JavaScript, there is no way to detect when a window is minimized.
You could try detecting a resize or blur event on the window, however those can be triggered by things other than a minimize.
Upvotes: 0
Reputation: 4087
From a quick search it looks like you can attach an event to the windows resize event, then call the required toggle functions from there as usual. I havnt actually tested the linked sample though...
$(window).bind('resize', function() { ....
http://snipplr.com/view/6284/jquery--window-on-resize-event/
Upvotes: 1