Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Warn when leaving a new thread/post/editing posts
#1
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 --"
#2
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>
#3
@Stefan C.
Wanna use this too. Which templates do you mean exactly?
And is this working for every browser?
Roses are red
violets are blue
sunflowers are yellow
i bet you were expecting something romantic but no
these are just gardening facts
#4
(2013-09-15, 01:31 PM)[email protected] 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
#5
(2013-09-15, 01:41 PM)martec Wrote:
(2013-09-15, 01:31 PM)[email protected] 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
Paul King
MyBB version: 1.8.21
Forum: www.nzarchitecture.net.nz
Webpage: www.prime.net.nz
#6
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!

   
#7
(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.
No longer involved in the MyBB project.
#8
Thank you, sorry!


Forum Jump:


Users browsing this thread: 1 Guest(s)