Get base URL

JavaScript, String, Browser, Regexp · Jan 3, 2021

Gets the current URL without any parameters or fragment identifiers.

const getBaseURL = url => url.replace(/[?#].*$/, '');
// ''

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub.

More like this

  • JavaScript Browser

    Select, traverse and manipulate DOM elements with this collection of JavaScript ES6 snippets.

    Collection · 106 snippets

  • Check if absolute URL

    Checks if the given string is an absolute URL.

    JavaScript, String · Oct 20, 2020

  • URL parameters as object

    Creates an object containing the parameters of the current URL.

    JavaScript, Browser · Oct 22, 2020

  • Change color lightness

    Changes the lightness value of an hsl() color string.

    JavaScript, String · Oct 31, 2020