I typically use the below function to return the root URL if I ever need this, but thought to ask if jQuery had a "one liner" way to do this ...
function getRootURL()
{
var baseURL = location.href;
var rootURL = baseURL.substring(0, baseURL.indexOf('/', 7));
// if the root url is localhost, don't add the directory as cassani doesn't use it
if (baseURL.indexOf('localhost') == -1)
{
return rootURL + "/AppName/";
} else {
return rootURL + "/";
}
}
The easiest way is to use a regex or split : url = "http://localhost/solo04/index.php?Route=checkout/checkout#shipping-method"; lastPart = url. split('? ')[1]; // grabs the part on the right of the ?
To find the base URL of your website, go to the site's front page. What you see in the address bar on your site's front page is the base URL of your website.
What about
document.location.hostname
You can just do:
alert(location.host)
With location.hostname, you don't get the port (if there's a special port like :8080).
To get the host, you would do this:
window.location.hostname
To get the context path:
window.location.pathname
And you can redirect the user with a querystring, like this -- preserves the hostname and port
window.location.href = window.location.pathname + "?variable=" + theValue;
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