I have a website that users with an affiliate URL often visit, for example:
https://demowebsite.com/?ref=550
There is a link that initially has an URL:
https://demowebsite.com/register
<a href="https://demowebsite.com/register" id="reg" class="btn btn-info">Register</a>
How can I make that if there is a part with a ref ID in the address bar like https://demowebsite.com/?ref=550
, then the href is transformed into the following by click:
https://subdomain.demowebsite.com/ref/
and add the ref ID at the end as an append:
https://subdomain.demowebsite.com/ref/550
And if there is no affiliate part in the address bar, then the link would remain the same.
<a href="https://demowebsite.com/register" id="reg" class="btn btn-info">Register</a>
I would be grateful for any help.
question from:
https://stackoverflow.com/questions/65918813/change-button-href-depending-on-the-address-bar-url 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…