ReedyBear's Blog

BearBlog: Prevent accidentally leaving 'New Post' page

When you publish or save as draft or delete, there will be no extra confirmation. If you close the tab or otherwise navigate away, it should ask you to confirm.

Visit your dashboard at https://bearblog.dev/dashboard/customise/ and put in the following code under 'Dashboard footer content':

<script type="text/javascript">
    window.onbeforeunload = function(event) {
       console.log(event.originalTarget);
       if (event.originalTarget.activeElement.getAttribute('type')=='submit'
       || event.originalTarget.activeElement.innerText=='Delete'){
           //console.log("Allow page exit, do nothing");
       } else {
           // console.log("Confirm page exit");
           return "Are you sure you want to navigate away?";
       }    
}
</script>

#bearblog