Skip to content

Instantly share code, notes, and snippets.

@doublnt
Last active January 15, 2018 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doublnt/9c1f3dc8ad956c98e72a9e9d64af2146 to your computer and use it in GitHub Desktop.
Save doublnt/9c1f3dc8ad956c98e72a9e9d64af2146 to your computer and use it in GitHub Desktop.
Window on and focus demo
<!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>
<script id="jsbin-javascript">
// 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>');
});
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">// 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>');
});
});</script></body>
</html>
// 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>');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment