change inactive page title javascript

<script type="text/javascript" language="JavaScript">
window.addEventListener('focus', function() {
    document.title = 'Default page title';
});

window.addEventListener('blur', function() {
    document.title = 'Title when the page is inactive';
});
</script>