0

I've been trying to add url parameters like the ones in youtube https://www.youtube.com/watch?v=1dJT-99KpiI but I have no idea how to.

Relevant Node.js Server Code:

function(err, session) {
    var url = new URL(window.location.href);
    url.searchParams.append("sessionId",session.Id);
  }

Relevant Javascript Client-Side Code

url =  new URL(window.location.href);
var sessionId = url.searchParams.get("sessionId");
console.log(sessionId);
1
  • 1
    Been trying to add url parameters how? What code have you tried? Can you show an example? Commented Oct 31, 2019 at 20:07

3 Answers 3

1

Hi Dear You can pass parameters in this way

function functionName(parameter1, parameter2, parameter3) {
  // code to be executed
}

Sign up to request clarification or add additional context in comments.

3 Comments

Please describe in your answer, what was the problem, and how will this snippet solve it, to help others understand this answer5
Thanks Sir "FZs" i will follow your suggestions next time
"Chava G" Thanks :-)
1

I need more context, but you can use string literals, for example:

const id = 'Qe500eIK1oA';
const link = `https://www.youtube.com/watch?v=${id}`;

or just concat the string with the id

const link = 'https://www.youtube.com/watch?v=' + id;

and then you can use it like this, for example

window.open(link);

Comments

1

The most robust way to add a query string (the ?key=value&foo=bar part of a URL) to a URL in JS is using the built-in URL class and its URLSearchParams:

const url = new URL('https://youtube.com');
url.searchParams.append('v','1dJT-99KpiI');
console.log(url);

1 Comment

I'm trying to do this but between server side and client side scripts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.