Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Prevent accidentially closing the survey

Prevent accidentially closing the survey 2 years 6 months ago #106456

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Hey folks!

I used to use this to prevent (by first asking if the user is sure (s)he wants to leave) the usage of the browser's back button or the closing of the tab/window before completing the survey:
function goodbye(e) {
    if(document.limesurvey.move.value == '')
    {
    	if(!e) e = window.event;
    	//e.cancelBubble is supported by IE - this will kill the bubbling process.
    	e.cancelBubble = true;
    	e.returnValue = 'Sind Sie sicher, dass Sie die Seite verlassen möchten? Eingegebene Daten werden unter Umständen nicht gespeichert.'; //This is displayed on the dialog
 
    	//e.stopPropagation works in Firefox.
    	if (e.stopPropagation) {
    		e.stopPropagation();
    		e.preventDefault();
    	}
    }
}
window.onload=function() { document.limesurvey.move.value = ''; }
window.onbeforeunload=goodbye;

The variable document.limesurvey.move seems to have been removed in the current version (2.05+ b140302). Is there a good alternative? I wonder why this is not part of the core functionality because the survey can break on improper use of the back button - and also some people forget about the survey the already opened and are reminded before they close it... But anyways, I can solve it myself but find it hard to detect which activity is "proper use" and which is not.

Thank you very much!

Best
Jonsen
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 6 months ago #106616

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Is this really a non-issue for everyone else? What if someone wants to go back and uses the "back" button? Do you just accept that this participant will drop out of the survey because it will show "document expired"?

Please help me understand... Thanks!

Best
Jonsen
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107348

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Pleeeeeeease people, can you at least tell me why this doesn't seem to bother anyone?

Thank you very much!

Best
Jonsen
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107377

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
Hi,

Not sure it work on all browser, but you can use your own 'identifier'
Try this:
function goodbye(e) {
    if(!$('#submitted').length)
    {
    	if(!e) e = window.event;
    	//e.cancelBubble is supported by IE - this will kill the bubbling process.
    	e.cancelBubble = true;
    	e.returnValue = 'Sind Sie sicher, dass Sie die Seite verlassen möchten? Eingegebene Daten werden unter Umständen nicht gespeichert.'; //This is displayed on the dialog
 
    	//e.stopPropagation works in Firefox.
    	if (e.stopPropagation) {
    		e.stopPropagation();
    		e.preventDefault();
    	}
    	return 'Sind Sie sicher, dass Sie die Seite verlassen möchten? Eingegebene Daten werden unter Umständen nicht gespeichert.'; // For chrome
    }
}
window.onbeforeunload=goodbye;
 
$(document).on('click',".button,[name='move']", function(event){
    $('body').append('<input type="hidden" id="submitted" />');
});
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
Last Edit: 2 years 5 months ago by DenisChenu. Reason: // For chrome
The administrator has disabled public write access.
The following user(s) said Thank You: jonsen

Prevent accidentially closing the survey 2 years 5 months ago #107381

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
PS: for chrome/chromium ,

Seems you need a return

Something like this:
return 'Sind Sie sicher, dass Sie die Seite verlassen möchten? Eingegebene Daten werden unter Umständen nicht gespeichert.'; //This is displayed on the dialog
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107439

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
@Denis, thank you very much for your answer, I'll try it ASAP and come back here to report...


@EVERYONE: Does this not seem to be an issue for anyone else? If yes, why not?

Best
Jonsen
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107441

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
Hi,

Because : user are master of their browser. If user want to close their browser, let them close their browser, or click previous or reload etc ....

Maybe :)
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107443

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
NO I AM THEIR MASTER ;)

Just kidding... I just think especially the use of the "back" button often happens because people are used to it. Also, I'm not disabling functionality, just making sure that it really is what the user wants.

But yeah, I get your point and why such functionality might not be part of the original LS code. Still, I think it should be.

Best
Jonsen

(BTW: The code above does not seem to work yet, I will get back on that Monday...)
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107444

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
jonsen wrote:
(BTW: The code above does not seem to work yet, I will get back on that Monday...)
Tested in FireFox and Chromium : limesurvey.sondages.pro/631792/newtest/Y
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107450

  • david2013
  • david2013's Avatar
  • Offline
  • Senior Lime
  • Posts: 59
  • Thank you received: 7
  • Karma: 3
Hi Denis,

It works well. A quick question, why your survey is able to jump to different group without answer compulsory questions? Can you please show me how
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107456

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107466

  • david2013
  • david2013's Avatar
  • Offline
  • Senior Lime
  • Posts: 59
  • Thank you received: 7
  • Karma: 3
It seems it will jump to next compulsory question. If I have 50 questions on 50 different pages. Each question are compulsory. Now I want to test skip logic around Q40. Currently, I have to answer all the questions up to Q40. Are we able to let question index jump to Q40 directly? It will save a lot of time when testing.
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107467

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
No .... stop at first error, but don't stop at actual page.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107913

  • jonsen
  • jonsen's Avatar
  • Offline
  • Expert Lime
  • Posts: 83
  • Thank you received: 8
  • Karma: 1
Denis, thanks again for your solution! The reason why it did not work for me was that I changed the wrong template - d'oh! ;)

But I have one (I think quite important) addition to your code. In order for participants to be able to leave the survey without a message AFTER completing, I added another condition to the if-statement:
if(!$('#submitted').length && !$('#completed').length)
(It detects if the div with the id "completed" exists on that page.)

If you agree, can you please add it to your code?

Best
Jonsen
The administrator has disabled public write access.

Prevent accidentially closing the survey 2 years 5 months ago #107915

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9346
  • Thank you received: 1338
  • Karma: 386
Hi,

Plese fill free to update our wiki :
manual.limesurvey.org/Workarounds:_Surve...y_closing_the_survey

;)
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
The following user(s) said Thank You: jonsen
  • Page:
  • 1
  • 2
Time to create page: 0.283 seconds
Imprint                   Privacy policy                  Revocation information and revocation form