I have a URL like http://localhost/dms/mduserSecurity/UIL/index.php?menu=true&submenu=true&pcode=1235
.
I want to get the URL without the query string: http://localhost/dms/mduserSecurity/UIL/index.php
.
Is there any method for this in JavaScript? Currently I am using document.location.href
, but it returns the complete URL.
A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.
Yes, URL query string params are of type string. It's up to you to convert them to and from the type you need.
Try this:
let path = window.location.href.split('?')[0] console.log({path})
Read about Window.location
and the Location
interface:
const urlPieces = [location.protocol, '//', location.host, location.pathname] let url = urlPieces.join('') console.log({urlPieces, url})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With