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(/[?#].*$/, '');

getBaseURL('http://url.com/page?name=Adam&surname=Smith');
// 'http://url.com/page'

More like this

  • JavaScript Browser

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

    Collection · 101 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