• maxime

    (@max345)


    How can I use a link that will save the post before leaving?

    I tried this:

    link.onclick = function() {
        wp.data.dispatch("core/editor").savePost();
        location.href = myUrl;
    }

    but I still get the javascript alert (“Leave site? Changes you made may not be saved.”)

    This is working but very slow and poor experience:

    link.onclick = function(e) {
        e.preventDefault();    
        wp.data.dispatch("core/editor").savePost();
        setTimeout(function() {
            location.href = myUrl;
        }, 2000);
    }

    Any better solution?

    • This topic was modified 6 years ago by maxime.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there – I saw your post here, I just wanted to let you know, that I am with you that those prompts are annoying and thank you for trying to make it easier on your users.
    As I get the “Leave site?…” prompt even after I physically saved the draft, I just figured the browser and Gutenberg UI are not always communicating well. Sorry, I don’t have a solution for you. Did you figure it out in the meantime?

    Thread Starter maxime

    (@max345)

    Sorry I couldn’t find any work around and gave up on this. But I vote up for simply removing the prompts: if you leave the edior by mistake, you can recover the content pretty easily thanks to the autosave.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Link that will save the post before leaving’ is closed to new replies.