Sometimes, we want to get the URL without query string parameters for different reasons. So you can get it in different ways. Let’s check the code below.
Method 1: By using URL object
I have already discussed in my previous article that how to create URL object. You can follow it. So let’s check how to get only URL using URL Object.
//get the current url
var current_url = window.location.href;
//create a new object
var url = new URL(current_url);
So, you will get
Method 2: By using split
var url = window.location.href.split('?');