WordPress – Disable “Are you sure you want to navigate away from this page?” when saving custom post

I have a WordPress site very customized where there are a lot of contributors and lots of posts are published. When you try to publish/update a custom post it displays a popup saying “The changes you made will be lost if you navigate away from this page. Are you sure you want to leave this page?”.

This only happens when the modified/new content of the post is in custom fields corresponding to “Advanced Custom Fields” plugin. This popup is very annoying for the contributors. So I would like to know if is possible to disable this popup or any way to fix that.

Read More

Thanks.

Related posts

Leave a Reply

4 comments

  1. A more general answer in regards to WP’s confirmation dialog:

    Within wp-admin/js/post.js of WordPress-4.8 on line 481 you can find the mechanism behind the “navigate away” confirmation dialog.

    The event: beforeunload.edit-post is initiated via jQuery’s .on() function. jQuery gives you the ability to unbind event handlers via the .off() function.

    By adding the following to your Javascript, you can disable this confirmation dialog when needed. WordPress itself also uses it when you hit the submit (Publish) button on a post for example.

    // Prevent WP from asking confirmation to navigate away from the current post.
    jQuery(window).off( 'beforeunload.edit-post' );
    

    P.S. WordPress specific questions should be asked at: https://wordpress.stackexchange.com/

  2. Still valid on wordpress 5.9
    So, I was trying to track down how WordPress itself handled this.
    Here is what I found out:
    There is an eventListener on publish or edit button of WordPress.
    That actually runs the below code:

    jQuery(window).off("beforeunload.edit-post") 
    

    So, Using the same way you also can disable that.