Skip to main content

Remove hostname from URL in javascript

You can remove hostname from URL in javascript. Sometimes you have to remove the hostname from the URL in that case it will help you to remove the hostname (domain name) from the URL in javascript

  • Remove hostname from url in javascript using URL() constructor

    var url = new URL('')



    This code snippet return the url with pathname (without hostname) using URL() constructor method.

  • Back to code snippet queries related javascript