4

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

1

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

<?php
function wpse35898_admin_head() {  
    ?> 
    <script type="text/javascript"> 
        window.onbeforeunload = function() {};
    </script> 
    <?php 
} 
add_action( 'admin_head' , 'wpse35898_admin_head' ); 
?>
3
  • 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? 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? 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. Mar 16, 2012 at 0:34
0
tinyMCE.init({
     .................................

     .................................

    autosave_ask_before_unload:false
  })
1
  • Please edit your answer, and add an explanation: why could that solve the problem?
    – fuxia
    Mar 19, 2018 at 9:05
0

as this page

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

tinymce.init({
        mode: 'textareas',
        menubar: false,
        statusbar: false,
        language: 'sv_SE',
        autosave_ask_before_unload: false,
        ...

and you must be add bottom code in your page:

<script>
window.onbeforeunload = function() {};
</script>
2
  • Do you really need both? I'm not that comfortable just removing all onbeforeunload handlers, which may not just be TinyMCE.
    – Rup
    Jul 1, 2019 at 10:53
  • In my case both of them needed. 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.