-1

This is about a password reset link sent to the email from firebase. I want to get the oobCode from it. But when I obtain the url of the page , it gives me the local address not the actual link I clicked in my email.Please help

https://example.com/usermgmt?mode=resetPassword&oobCode=ABC123&apiKey=AIzaSy...&lang=fr

This link actually loads the reset_pwd.html in my website. So when I try to get window.location.href , it doesnt give me the actual address displayed in the address bar.

This is what I have tried so far. But I realised I' m trying to split the local address of the web page http://127.0.0.1:80/reset_username

function func() {
  var s = window.location.href;
  ResponseURL = window.location.href;
  var domain = ResponseURL.split('=');
  alert(s);;

}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 3
    Possible duplicate of [How to get parameters name and value from url using jquery?](https://stackoverflow.com/questions/55057130/how-to-get-parameters-name-and-value-from-url-using-jquery) – User863 Apr 09 '19 at 11:51
  • I m not using JQuery , I want a solution in Javascript – Andria Peters Apr 09 '19 at 11:52
  • 1
    [Get URL variables with Javascript](https://css-tricks.com/snippets/javascript/get-url-variables/) If only someone had invented Google or something like that – Jeremy Thille Apr 09 '19 at 11:55
  • Possible duplicate of [Split url with javascript](https://stackoverflow.com/questions/15538435/split-url-with-javascript) – Noldy Apr 09 '19 at 12:00
  • Well , location href isnt returning the lengthy address I want to split. it is returing the local address – Andria Peters Apr 09 '19 at 12:00
  • 1
    Possible duplicate of [How to get the value from the GET parameters?](https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters) – Daniel Beck Apr 09 '19 at 13:27
  • Thank You for all the suggestions. There was a error in my code and now it is working fine – Andria Peters Apr 09 '19 at 18:27

1 Answers1

0

You can get it using URL.searchParams.get():

function getUrlParam(key, urlString = window.location.href) {
  let url2 = new URL(urlString);
  return url2.searchParams.get(key);
}


const url = `https://example.com/usermgmt?mode=resetPassword&oobCode=ABC123&apiKey=AIzaSy&lang=fr`;
console.log(getUrlParam('oobCode', url));

// Can be used without providing the URL, like:
// getUrlParam('oobCode');
Miroslav Glamuzina
  • 4,472
  • 2
  • 19
  • 33