Last active
January 15, 2018 10:30
-
-
Save doublnt/9c1f3dc8ad956c98e72a9e9d64af2146 to your computer and use it in GitHub Desktop.
Window on and focus demo
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> | |
<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> |
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
// 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