Search code examples
wordpresscustom-post-typeonbeforeunloadmeta-boxes

How to disable the event that is executed before leaving the page?


I'm building a plugin for wordpress, I have a custom post type and several meta-boxes. In a meta-box I have a button to publish or update custom.

This is something of my code:

add_meta_box(
    'my_meta_boz'
    ,__( 'My title meta box', 'my-plugin' )
    ,array( $this, 'render_my_meta_box' )
    ,'my-screen'
    ,'normal'
    ,'high'
);

In my 'render_my_meta_box' function I have my custom button:

<p>
    <input type="submit" name="publish" id="publish" value="Save changes" />
</p>

And I have no problem with that, except that saving or updating shows a confirmation dialog.

enter image description here

I want to remove this dialog box because the original button does not show any confirmation. How can I delete this dialog?

Try the following, but it did not work:

<input type="submit" name="publish" id="publish" value="Save changes" onclick="javascript:window.onbeforeunload = null;"/>

I have also used the 'submit_button ()' function, but it also shows the confirmation dialog.


Solution

  • You can try this solution, it is not very clean but it works. Call the event click on the original button.

    <input type="submit" value="Save changes" onclick="window.document.getElementById('publish').click();"/>