0

I want to use (base64 encoded key) as URL parameter

like: mydomain.com/?key=cHVyY2hhc2VwcmljZT0zNCQ=

that returns: purchaseprice=34$

I read How to get base64 encoded... but it did not help.

here is my working code without base64:

<input type="text" id="price" />
<script>
const url = new URL(window.location);
document.querySelector('#price').value = url.searchParams.get('purchaseprice');
</script>

and in Codepen

James Martinez
  • 191
  • 2
  • 11

2 Answers2

2

If you're expecting the return value of purchaseprice to be base64 encoded then you'll need to use the atob() function:

<input type="text" id="price" />
<script>
const url = new URL(window.location);
document.querySelector('#price').value = atob(url.searchParams.get('purchaseprice'));
</script>

Details here: Base64 Encoding / Decoding in JavaScript.

Example: CodePen

Pseudonymous
  • 839
  • 5
  • 13
0

thanks to cptcoathanger

i did it With this Simple code.

var fdurl = new URL(window.location);
var fdunc = fdurl.searchParams.get('key');
var url = "https://codepen.io/shahabarvin/pen/JmzyZq?" + window.atob(fdunc); 
document.querySelector('#price').value = new URL(url).searchParams.get("purchaseprice");
<input type="text" id="price" />

Codepen