-2

For example, I have a URL-

website.com/page/?var=20

I want to get the "var" variable from the URL by JS

Btw, my real URL is-

https://bipit2.pranaypro21292.repl.co/d21292auth/?code=pimWoHEuV7fgKEVQMTntRnzXqVla3G&guild_id=824947028609859614&permissions=0

and I want to get the "guild_id" variable from the URL.

BipityDip
  • 1
  • 1
  • 1
    Does this answer your question? [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – CBroe Apr 07 '21 at 09:41
  • Please do a bit of basic research, before you ask. Your question title typed into Google verbatim, would have easily led to the mentioned duplicate already. – CBroe Apr 07 '21 at 09:41
  • `window.location.query`? – evolutionxbox Apr 07 '21 at 09:43
  • Kindly search for a solution before asking a question to avoid duplicate questions. – domii Apr 07 '21 at 09:47

1 Answers1

0

u can get the last path of ur url by using

var str = window.location.href;
res = str.split('/');
last = res[res.length-1]

the rest of it maybe remove the rest of unwanted char like "?", "=", and the data behind "="

this is not efficient but this is all i know, hope it works

update : u can also use : window.location.search to get the last path

UDIN
  • 11
  • 5