Window.focus document.focus and blur events

From Code Trash
Jump to: navigation, search
if (/*@cc_on!@*/false) { // check for Internet Explorer
	document.onfocus = focs;
} else {
	window.onfocus = focs;
function focs()
	var aye = getCookie('shippingaddress')
			if(so.status)document.getElementById('').innerHTML = so.content

The following is copied from the following site.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function onBlur() {
	document.body.className = 'blurred';
function onFocus(){
	document.body.className = 'focused';
if (/*@cc_on!@*/false) { // check for Internet Explorer
	document.onfocusin = onFocus;
	document.onfocusout = onBlur;
} else {
	window.onfocus = onFocus;
	window.onblur = onBlur;
<style type="text/css">
.focused #focused, .blurred #blurred { display: inline }
.focused #blurred, .blurred #focused { display: none }
.focused {
	background: white;
	color: black;
.blurred {
	background: black;
	color: white;
<body class="focused">
<h1>window.onfocus() and window.onblur() demo</h1>
<p>Switch to a different program to blur this page.</p>
<p>You can also just click into the location bar (except in Safari).</p>
<p>Click this page again to focus it.</p>
<p>When blurred, this page will have a black background with white text.</p>
<p>The window is currently <span id="focused">FOCUSED</span><span id="blurred">BLURRED</span>.
<p><a href="">Click here for a discussion of this demo.</a></p>
<p id="log"></p>