Home > other >  Can i create with Javascript a page with diferents URL?
Can i create with Javascript a page with diferents URL?

Time:09-23

So basically i want to create one web page, eg: www.page.com, but i want to create a qr code that gets you in the web, to make orders, so i want the page to be. www.page.com/1..2...3, so every qr code gets you to the same page. And I want to be 1..2..3 so i can know who ordered. I dont want to make a user to be registered, i know that could make thing a lot easier. The real use for this is that people can order thing by scanning the code, get what they want for a list and wait in the table where de qr code is.

CodePudding user response:

You can pass a parameter through the URL. So the URL would look something like this:

https://example.com?person=123

Then you can use the following to get the id

let params = (new URL(document.location)).searchParams;
let personId = params.get('person');

CodePudding user response:

You could get it done using query strings in the url e.g.

www.example.com?id=1

That url will head you to your site and you can identify your customer's table using javascript and parsing the query string variable

window.addEventListener('load',  () => {
    let table;
    table = getQueryVariable('table');
    document.getElementById("idTable").innerHTML = table;
    console.log(table)
});

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i = 0; i < vars.length; i  ) {
        var pair = vars[i].split('=');
        if (decodeURIComponent(pair[0]) == variable) {
            return decodeURIComponent(pair[1]);
        }
    }
    console.log('Query variable %s not found', variable);
}
<link href="https://cdn.simplecss.org/simple.min.css" rel="stylesheet"/>

  <h1>Welcome</h1>
  <p>You're ordering from table <span id="idTable"></span></p>

  • Related