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>
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
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" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.