How to ask your readers - Are you sure you want to leave/navigate?

I have seen many blogs and websites asking their user to confirm before they leave the page. I personally don't use that feature but if you want to have that feature on your blogger blog, I am going to teach you how to do that.

<script type="text/javascript" 
language="javascript">
var areYouReallySure = false;
var internalLink = false;
function areYouSure() {
if(allowPrompt)
   {
if (!areYouReallySure && !internalLink &&
 true) {
areYouReallySure = true;
return "YOUR MESSAGE TO READERS";
}
}
   else
   {
      allowPrompt = true;
   }
}

var allowPrompt = true;
window.onbeforeunload = areYouSure;

</script>

Replace YOUR MESSAGE TO READERS with the text that you want your readers to see when they click on the close button of the tag or browser.

Copy the code and go to html template editor for your blogger blog.

Find  the following code:

<body expr:class='&quot;loading&quot; + data:blog.mobileClass'>

Just below this code, paste the copied code. Now whenever user will try to navigate from your page he/she will she the following alert box.


WARNING: This code will be executed during the editing and preview work. So it can irritate to also.