How do I get the exact href value just without their domain?

I am having trouble getting the exact value of the href alone. Here is the code:

Link:
<a href="monthly"></a>

Script:
'a': function(target, process){
    if(process == "stripe"){
        document.location.href = "/accounts/stripe/payment"+target[0].href;
    }else{
        ......
    }
},

      

If I run this output it will be:

http://localhost:8000/accounts/stripe/paymenthttp://localhost:8000/monthly/

      

Note that localhost is duplicate. How do I get only "monthly" in the href without that localhost? I'm trying to target only but undefined. I'm trying to use target [1], but it doesn't work.

+3


source to share


2 answers


It is little known (possibly) that most browsers convert Anchor nodes to Location objects. This way you can access all the details available for the location,



 document.location.href = "/accounts/stripe/payment"+target[0].pathname;

      

+3


source


Try target[0].getAttribute("href")

to get the literal content of the attribute.



+6


source







All Articles