MyBB Community Forums

Full Version: Warn when leaving a new thread/post/editing posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So, on a board I administrate (many of the threads are very line tuturials, with a good bit of thought/time put into them), and they accidentally close their web browser/tab. It'd be neat for MyBB to warn before leaving the tab/browser.

"Are you sure you want to navigate away from -- url --"
Just put the following in the template for the thread/post editing

<script>

    var userIsEditingSomething; // set this if something crazy happens
        oldOnBeforeUnload = window.onbeforeunload;

    window.onbeforeunload = function () {
        // attempt to handle a previous onbeforeunload
        if ('function' === typeof oldOnBeforeUnload) {
            var message = oldOnBeforeUnload();
            if ('undefined' !== typeof message) {
                if (confirm('string' === typeof message ? message : 'Are you sure you want to leave this page?')) {
                    return; // allow user to exit without further annoying pop-ups
                }
            }
        }
        // handle our own
        if (userIsEditingSomething) {
            return 'Are you sure you want to exit?';
        }
    };

</script>
@Stefan C.
Wanna use this too. Which templates do you mean exactly?
And is this working for every browser?
(2013-09-15, 01:31 PM)k1R@ Wrote: [ -> ]@Stefan C.
Wanna use this too. Which templates do you mean exactly?
And is this working for every browser?

probably

showthread_quickreply
private_send
newreply
newthread
editpost
(2013-09-15, 01:41 PM)martec Wrote: [ -> ]
(2013-09-15, 01:31 PM)k1R@ Wrote: [ -> ]@Stefan C.
Wanna use this too. Which templates do you mean exactly?
And is this working for every browser?

probably

showthread_quickreply
private_send
newreply
newthread
editpost

Doesn't seem to work for Chrome 32 or IE 11 if pasted in to theme NewReply template
Hi everyone,
That would be the problem is that the "new response" icon is missing and there is only one label instead
Can anyone help?
Thank you!

[attachment=31159]
(2014-03-08, 03:25 PM)Robb Wrote: [ -> ]Hi everyone,
That would be the problem is that the "new response" icon is missing and there is only one label instead
Can anyone help?
Thank you!

Please create your own thread.
Thank you, sorry!