I was wondering if it would be possible to get the page name from the address bar using jquery or javascript. I know this can be done using PHP but don't really want to as it is only a html website.
I.e. if the address is www.mywebsite.com/hello.htm
how do I get the hello.htm
part out of the address.
Thanks for any help you can provide.
You can use Location object property of the Window object to get these details. href => This will return the entire URL displaying in the address bar. host => This will return the hostname and port of the URL in address bar. hostname => This will return only the hostname of the URL in address bar.
Try this
location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
location.pathname
gives the part(domain not included) of the page url. To get only the filename you have to extaract it using substring
method.
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