Anyone know of a nice way to disable that pop-up dialogue when exiting the post-editor? It says "This page is asking you to confirm that you want to leave - data you have entered may not be saved."

Nice feature, but annoying in certain blogs where I have to edit a ton of posts

3 Answers 3


You can use the method described here. Add the following to your functions.php

function wpse35898_admin_head() {  
    <script type="text/javascript"> 
        window.onbeforeunload = function() {};
add_action( 'admin_head' , 'wpse35898_admin_head' ); 
  • I tried your code. I can see where it is inserting the script into the head but still no joy. Any thoughts? have you seen this in action? Commented Dec 8, 2011 at 21:55
  • I haven't tried, but it should overwrite the window.onbeforeunload event so nothing happens. Can you track that the function is called with firebug? Commented Dec 9, 2011 at 13:39
  • 1
    This would work, except that the window.onbeforeunload method is redefined every time the tinymce box gets out of sync with the autosaved post. If you want to prevent it from occuring again, I think you should be able to just change the text of the confirmation message to true. ie. autosaveL10n.saveAlert = true. Commented Mar 16, 2012 at 0:34


  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Commented Mar 19, 2018 at 9:05

as this page

you must to add "autosave_ask_before_unload: false" in init of tinymce(as bottom code):

        mode: 'textareas',
        menubar: false,
        statusbar: false,
        language: 'sv_SE',
        autosave_ask_before_unload: false,

and you must be add bottom code in your page:

window.onbeforeunload = function() {};
  • Do you really need both? I'm not that comfortable just removing all onbeforeunload handlers, which may not just be TinyMCE.
    – Rup
    Commented Jul 1, 2019 at 10:53
  • In my case both of them needed. Commented Jul 3, 2019 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.