The Goal:
When a user navigates away from the browser window they’re on (ie: your website to someone else’s), this code snippet will change the text to something catchy that will bring them back.

Requirements:

  • jQuery / JS

Before

After

jQuery

Add this to your custom scripts. Make sure you have jQuery installed.

[cc lang=”javascript”]
// Browser Navigate Away Code
$(function() {
// Get page title
var pageTitle = $(“head title”).text();

//alert(pageTitle);

// Change page title on blur
$(window).blur(function() {
$(“title”).text(‘Not So Fast!’);
});

// Change page title back on focus
$(window).focus(function() {
$(“title”).text(pageTitle);
});
});
[/cc]

Share This