SyntaxFix
Write A Post
Hire A Developer
Questions
Here's an approach using the URL() interface:
new URL(location.pathname, location.href).href