Demonstrates how to handle the window's focus
and blur
events with jQuery.
Last active
March 20, 2021 04:15
-
-
Save RunnerRick/7645236 to your computer and use it in GitHub Desktop.
Demonstrates how to handle the window's `focus` and `blur` events with jQuery.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"predef": [ | |
"$" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Handle jQuery's `document ready` event. | |
$(document).ready(function () { | |
// Define an event handler for the window's `focus` event. | |
$(window).on('focus', function () { | |
// Append this text to the `body` element. | |
$('body').append('The window has focus.<br>'); | |
}); | |
// Define an event handler for the window's `blur` event. | |
$(window).on('blur', function () { | |
// Append this text to the `body` element. | |
$('body').append('The window has lost focus.<br>'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Window Focus Example</title> | |
</head> | |
<body> | |
<p>Click anywhere in the browser's viewport to trigger the <code>focus</code> event.</p> | |
<p>Click on something other than the browser's viewport to trigger the <code>blur</code> event.</p> | |
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment