- Posts: 4
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Use Javascript, find if page is loaded for the first time, or due to errors
- crafter
- Topic Author
- Offline
- New Member
Less
More
10 years 3 weeks ago #106967
by crafter
Use Javascript, find if page is loaded for the first time, or due to errors was created by crafter
Hi all
Is there a way, using Javascript, to determine if page is being loaded for the first time, or due to errors on the page.
I have a small Javascript function that attaches to the page load, so that a message appears for a few seconds before the page is shown. If the page is completed with validation errors, the Javascript is reloaded and the message is displayed again.
However, I would want the message to not display if the page is being returned to due to validation errors.
How can I determine if a page is being reloaded due to errors.
Is there a way, using Javascript, to determine if page is being loaded for the first time, or due to errors on the page.
I have a small Javascript function that attaches to the page load, so that a message appears for a few seconds before the page is shown. If the page is completed with validation errors, the Javascript is reloaded and the message is displayed again.
However, I would want the message to not display if the page is being returned to due to validation errors.
How can I determine if a page is being reloaded due to errors.
The topic has been locked.
- crafter
- Topic Author
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
10 years 3 weeks ago - 10 years 3 weeks ago #106968
by crafter
Replied by crafter on topic Use Javascript, find if page is loaded for the first time, or due to errors
Actually, I may have found a solution.
The secret may be in these lines in the survey_runtime.js file
A page loaded with errors contains this code (as an example)
whereas a page with no errors contains an empty startPopups array
therefore, checking for an empty startPopups array will get me the solution I require, it seems.
The secret may be in these lines in the survey_runtime.js file
Code:
function showStartPopups(){ if(typeof showpopup=="undefined"){showpopup=1;} if(typeof startPopups=="undefined"){startPopups=[];} if(showpopup){ $.each(startPopups,function(key, text){ alert($("<div/>").html(text).text());// Parse HTML because of &#039; }); } }
A page loaded with errors contains this code (as an example)
Code:
showpopup=1; startPopups=["One or more mandatory questions have not been answered. You cannot proceed until these have been completed.","One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid."];
Code:
showpopup=1; startPopups=[]
therefore, checking for an empty startPopups array will get me the solution I require, it seems.
Last edit: 10 years 3 weeks ago by crafter. Reason: removed data from startPopups
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
10 years 3 weeks ago #106972
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Use Javascript, find if page is loaded for the first time, or due to errors
And you can replace showStartPopups function in template.js to test it.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.