- Posts: 59
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Prevent accidentially closing the survey
- Sweden
- Offline
- Senior Member
Less
More
4 years 2 weeks ago - 4 years 2 weeks ago #196101
by Sweden
Replied by Sweden on topic Prevent accidentially closing the survey
Wow. Thank you - that is very kind of you!
I have now done some testing with your code, on a PC with windows and an old iPad, both with different browsers. It's a bit confusing because there are so many combinations (devices/browsers). However, on the PC, another tab opens and quickly closes again, then the file download menu opens (so that is good, although it would be even better without the tab flickering).
On iPad, another tab opens and just shows the PDF, instead of showing the download-file-popup-window. The user may assume that the PDF has been downloaded and then closes the two tabs (and then the user will have no PDF file). Problem is also that none of the browsers I have tested on iPad shows the warning "Are you sure you want to quit the survey?" so it is easy for the user to lose the results there.
Do you have any suggestions how to change the just mentioned behavior? Also, no warning is shown on PC if users close their browser/tab, unless they scroll down a bit first. I wonder what has changed since the solution in the wiki no longer work. I don't think it is something special with my installation.
If you have time for another look - here is the code from my custom.js. I must have found it in this thread some time ago...
I have now done some testing with your code, on a PC with windows and an old iPad, both with different browsers. It's a bit confusing because there are so many combinations (devices/browsers). However, on the PC, another tab opens and quickly closes again, then the file download menu opens (so that is good, although it would be even better without the tab flickering).
On iPad, another tab opens and just shows the PDF, instead of showing the download-file-popup-window. The user may assume that the PDF has been downloaded and then closes the two tabs (and then the user will have no PDF file). Problem is also that none of the browsers I have tested on iPad shows the warning "Are you sure you want to quit the survey?" so it is easy for the user to lose the results there.
Do you have any suggestions how to change the just mentioned behavior? Also, no warning is shown on PC if users close their browser/tab, unless they scroll down a bit first. I wonder what has changed since the solution in the wiki no longer work. I don't think it is something special with my installation.
If you have time for another look - here is the code from my custom.js. I must have found it in this thread some time ago...
Code:
$(document).on('ready pjax:scriptcomplete',function(){ /** * Code included inside this will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute * @see https://learn.jquery.com/using-jquery-core/document-ready/ */ }); //FEATURES: (2015-03-27) Now with fix for iframes (e.g. file uploader) and the template editor function goodbye(e) { if(!$('body', top.document).hasClass('submitted') && !$('#completed').length && !$('.templateeditor', top.document).length) { //check if a button was used to navigate OR the survey is completed OR the template is displayed in the template editor if(!e) e = window.event; //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = 'Are you sure you want to quit this survey?'; //This is displayed on the dialog for IE //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } return 'Are you sure you want to quit this survey?'; // For chrome } } window.onbeforeunload = goodbye; $(document).on('click', '.button, .changelang, [name="move"]', function(event){ //added .changelang here, please add other classes if you know which should be allowed to navigate $('body', top.document).addClass('submitted'); }); (window).on('beforeunload', function(){ var c=confirm(); if(c){ return true; } else return false; });
Last edit: 4 years 2 weeks ago by Sweden.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
4 years 2 weeks ago - 4 years 2 weeks ago #196133
by tpartner
- developer.mozilla.org/en-US/docs/Web/API...w/beforeunload_event
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Prevent accidentially closing the survey
You cannot override the iPad browser behaviour.Do you have any suggestions how to change the just mentioned behavior?
This is the expected behaviour. The MDN documentation for the beforeunload event states "Note: To combat unwanted pop-ups, browsers may not display prompts created in beforeunload event handlers unless the page has been interacted with, or may even not display them at all."Also, no warning is shown on PC if users close their browser/tab, unless they scroll down a bit first.
- developer.mozilla.org/en-US/docs/Web/API...w/beforeunload_event
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 2 weeks ago by tpartner.
The following user(s) said Thank You: Sweden
The topic has been locked.
- krosser
- Offline
- Elite Member
Less
More
- Posts: 222
- Thank you received: 10
3 years 11 months ago #198290
by krosser
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
Replied by krosser on topic Prevent accidentially closing the survey
Can someone please suggest which class needs to be added to the code for excluding "Resume later" option?
I have managed to exclude the Index menu by adding class '.dropdown-toggle':
I think I have tried everything I could find and also added my own classes, but it simply did not work...
I have managed to exclude the Index menu by adding class '.dropdown-toggle':
Code:
$(document).on('click', '.button, .changelang, .dropdown-toggle, [name="move"]', function(event){ //added .changelang here, please add other classes if you know which should be allowed to navigate $('body', top.document).addClass('submitted'); });
I think I have tried everything I could find and also added my own classes, but it simply did not work...
I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.