Formulaire

Stocker les paramètres d'URL dans le local storage

<script>
function saveQueryParams() {
  const existingParams = JSON.parse(localStorage.getItem('queryParams')) || {};

  const queryString = window.location.search;

  if (queryString) {
    const newParams = {};
    const urlParams = new URLSearchParams(queryString);

    urlParams.forEach((value, key) => {
      newParams[key] = value;
    });

    const params = { ...existingParams, ...newParams };

    localStorage.setItem('queryParams', JSON.stringify(params));
  }
}

function loadQueryParams() {
  let params = {};

  if (localStorage.getItem('queryParams')) {
    params = JSON.parse(localStorage.getItem('queryParams'));
  }
  return params;
}

saveQueryParams();

loadQueryParams();
</script>

Etape 1 - Ajouter le script sur la page ou le projet Webflow

<!-- Scripts by Justa | Save Query Params on Local Storage -->
<script src="https://cdn.jsdelivr.net/npm/@justaa/scripts/dist/forms/save-params-local-storage.js"></script>
<script>
function saveQueryParams() {
  const existingParams = JSON.parse(localStorage.getItem('queryParams')) || {};

  const queryString = window.location.search;

  if (queryString) {
    const newParams = {};
    const urlParams = new URLSearchParams(queryString);

    urlParams.forEach((value, key) => {
      newParams[key] = value;
    });

    const params = { ...existingParams, ...newParams };

    localStorage.setItem('queryParams', JSON.stringify(params));
  }
}

function loadQueryParams() {
  let params = {};

  if (localStorage.getItem('queryParams')) {
    params = JSON.parse(localStorage.getItem('queryParams'));
  }
  return params;
}

saveQueryParams();

loadQueryParams();
</script>
Copier

Etape 2 - Ajouter les attributes correspondants

Aucun - Aucun attribute nécessaire

Tuto, template & scripts

<script>
function saveQueryParams() {
  const existingParams = JSON.parse(localStorage.getItem('queryParams')) || {};

  const queryString = window.location.search;

  if (queryString) {
    const newParams = {};
    const urlParams = new URLSearchParams(queryString);

    urlParams.forEach((value, key) => {
      newParams[key] = value;
    });

    const params = { ...existingParams, ...newParams };

    localStorage.setItem('queryParams', JSON.stringify(params));
  }
}

function loadQueryParams() {
  let params = {};

  if (localStorage.getItem('queryParams')) {
    params = JSON.parse(localStorage.getItem('queryParams'));
  }
  return params;
}

saveQueryParams();

loadQueryParams();
</script>
Copier

Etape 2 - Ajuster le code pour votre besoin

Copié dans le presse-papiers
Logo Justa

Progressez sur Webflow

Oops! Une erreur s'est produite lors de la soumission du formulaire.