Here is a quick code to get the current URL of a page with Javascript:-
var current_url = location.href;
Here is another way:-
var current_url = document.URL;
Suppose, you have query string in your URL and you only want to get the actual URL without the query string.
Here is the code for this:-
var url = location.href;
var url_parts = url.split(‘?’);
var main_url = url_parts[0];
Hope this helps. Thanks.