Run function if window is not active
<p>I'm currently developing a small conversation system. </p>

<p>When a user writes a new message, the title of the page changes to <em>New Message</em>, which is intended.</p>

<p>However, if the window is active when the message is received, the title should <strong>not</strong> be updated.</p>

<p>Currently, it will display the <em>New Message</em> regardless of the window is active or not, and only removes it again when a user changes tab and back.</p>

<p>How do I make it only run the <code>if (newCount !== messagesCount)</code> function if the window is <strong>not</strong> active?</p>

<p>Here's the current code:</p>

<pre><code>if (newCount !== messagesCount) {
    document.title = 'New Message - ' + title;
}

$(window).focus(function() {
    document.title = title;
});
</code></pre>
