Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#24145 closed enhancement (duplicate)

Confirm page close when writing on WordPress.org forums

Reported by: daedalon's profile Daedalon Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: WordPress.org Site Keywords:
Focuses: Cc:

Description

When writing on WordPress.org forums, sometimes long and well thought-out replies are lost due to accidental page closing. This causes countless amounts of work lost within the WordPress community.

There should be a confirmation dialog to prevent accidental page closing after user has entered something in the new post form.

Change History (6)

#1 @Daedalon
12 years ago

Here's a jQuery solution for confirming page close when any of the new post fields have been modified.

var requireCloseConfirmation = false;
function confirmPageClose(){
	if ( requireCloseConfirmation ) {
		return 'Are you sure you want to close this page? All changes will be lost.';
	}
}
jQuery('#postform input[type=text], #postform select, #postform textarea').change( function(){
	requireCloseConfirmation = true;
});
if( jQuery('#postform').length ){
	window.onbeforeunload = confirmPageClose;
}

This is triggered only if any one of these text areas has been changed and it has lost focus at least once. In other words this protects from most accidental closings except when user has changed only one field without clicking outside it or otherwise moving focus away from it. This should catch the vast majority of cases.

A timer-based script could cover even those that this does not. It would check every XX seconds if any of the fields are non-empty, and if, sets requireCloseConfirmation = true and terminates itself.

#2 @Daedalon
12 years ago

  • Type changed from defect (bug) to enhancement

#3 @SergeyBiryukov
12 years ago

  • Milestone changed from Awaiting Review to WordPress.org

#4 @Daedalon
12 years ago

Forgot one key thing from that JS, to not ask this confirmation on form submission:

$('input#postformsub').click( function(){
	requireCloseConfirmation = false;
});

Also, #postform input[type=checkbox] could be added to the monitored elements.

#5 @samuelsidler
11 years ago

  • Milestone WordPress.org deleted
  • Status changed from new to closed

Migrated to #meta155.

#6 @SergeyBiryukov
11 years ago

  • Resolution set to duplicate
Note: See TracTickets for help on using tickets.