I'm fetching img src attribute into a variable, while doing so I'm getting the complete url of the image, i want to remove domain name from the url
var imgurl = "http://nitseditor.dev/img/home/bg.jpg";
I want to have only img/home/bg.jpg
. How can I achieve it?
You can use URL
constructor.
This is an experimental technology
var url = new URL(imgurl);
console.log(url.pathname);
var imgurl = "http://nitseditor.dev/img/home/bg.jpg";
var url = new URL(imgurl);
console.log(url.pathname);
Browser Support
url = url.replace(/^.*\/\/[^\/]+/, '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With