Question:
How do you pass variables through a url, so that you can pick it up in Javascript / html? Any help / tutorials / replit examples appreciated.
To pass variables through url use this format:
url?variablename=value&anothervariable=anothervalue
To read these variables using JavaScript, try something like this:
const variables = {};
window.location.search.substr(1).split("&").forEach(function(variable) {
const temp = variable.split("=");
variables[temp[0]] = temp[1];
});
console.log(variables);
/*
{
variablename: "value",
anothervariable: "anothervalue"
}
*/
Thank you. That’s super helpful!
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.