Hi I tried to get the base URL and file path from my windows URL..But I cant get it..Please correct me..
The URL is:
http://sample.com:30023/portal/site/samples/index.jsp
The current output is: http://sample.com:30023/index.jsp?
The required output is: http://sample.com:30023/portal/site/samples/
Code used :
var baseURL = location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/";
add location.pathname, so it becomes
var baseURL = location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + location.pathname;
Also, why not simply use location.href to get the whole thing?
Good reference at https://developer.mozilla.org/en-US/docs/DOM/window.location
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