Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : Use Javascript, find if page is loaded for the first time, or due to errors

Use Javascript, find if page is loaded for the first time, or due to errors il y a 5 mois 21 heures #106967

  • crafter
  • Portrait de crafter
  • Hors ligne
  • Fresh Lemon
  • Messages : 17
  • Remerciements reçus 1
  • Karma: 0
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Use Javascript, find if page is loaded for the first time, or due to errors il y a 5 mois 21 heures #106968

  • crafter
  • Portrait de crafter
  • Hors ligne
  • Fresh Lemon
  • Messages : 17
  • Remerciements reçus 1
  • Karma: 0
Actually, I may have found a solution.

The secret may be in these lines in the survey_runtime.js file
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)
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."];
whereas a page with no errors contains an empty startPopups array
showpopup=1;
startPopups=[]

therefore, checking for an empty startPopups array will get me the solution I require, it seems.
Dernière édition: il y a 5 mois 20 heures par crafter. Raison: removed data from startPopups
L'administrateur a désactivé l'accès en écriture pour le public.

Use Javascript, find if page is loaded for the first time, or due to errors il y a 5 mois 17 heures #106972

  • DenisChenu
  • Portrait de DenisChenu
  • Hors ligne
  • Moderator Lime
  • Messages : 6276
  • Remerciements reçus 801
  • Karma: 241
And you can replace showStartPopups function in template.js to test it.
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.295 secondes
Donation Image