Skip to content

JDMcKinstry/jQuery.winFocus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

jQuery.winFocus

This cross-browser solution will better help you make callbacks whenever a Browser Window (Current Tab) loses or gains focus. It also seeks to tackle such issues as: duplicate calls, delaying trigger on page load, and Browser Window losing focus due to selection of another App (such as opening Calculator).


#Example Uses

Most Basic Use:

//	isVisible param in callback is TRUE or FALSE based on whether the Browser Window(Current Tab) has focus
$.winFocus(function(event, isVisible) {
	console.log("Combo\t\t", isVisible);
});

Delay Start:

//	passing `false` through will cause the callback to wait until first `blur`
$.winFocus(function(event, isVisible) {
	console.log("Combo\t\t", isVisible);
}, false);

Using 2 Callbacks

When using 2 callbacks, the first becomes lost focus, whereas the second becomes gained focus

$.winFocus(function(event) {
	console.log("Blur\t\t", event);
},
function(event) {
	console.log("Focus\t\t", event);
});

Object Callbacks:

Callbacks blur, focus, and blurFocus can be passed in an object. All 3 can be passed at once, if you desire such, but blurFocus is the only one with a isVisible parameter.

$.winFocus({
	//	will only fire when current tab loses focus
	blur: function(event) {
		console.log("Blur");
	},
	//	will only fire when current tab gains focus
	focus: function(event) {
		console.log("Focus");
	},
	//	will fire whenever current tab's focus changes
	blurFocus: function(event, isVisible) {
		console.log("Combo\t\t", isVisible);
	}
});

About

Simple way to determine if current browser window has focus!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published