onswitch from tab do something jquery

JavaScript
$(window).blur(function(e) {
	alert('You have moved from this tab/window.');
});
Source

Also in JavaScript: