Skip to content

Instantly share code, notes, and snippets.

@doublnt doublnt/index.html
Last active Jan 15, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.