Change text from url

https://YOURURL?to1=John+Cena&to2=$+200.000&to3=#1245691&to4=30+January+2024

How to implement that URL become to this page

Use the following code on Scene Load:

// Step 1: Get the full URL
const url = window.location.href;

// Step 2: Create a URLSearchParams object
const params = new URLSearchParams(url.split('?')[1]);

// Step 3: Loop through all parameters
params.forEach((value, key) => {
  // Find elements with the class name that matches the parameter name
  const elements = document.getElementsByClassName(key);
  
  // Assign the parameter value to each element
  for (let element of elements) {
    element.textContent = value;
  }
});

Assign the same class names to the elements that should show the values of the GET parameters as the names of the parameters themselves, for example: "to1" and so on.

4 Likes