Tutorial Get URL and URL Parts in JavaScript

JavaScript can access the current URL in parts. For this URL: http://css-tricks.com/example/index.html window.location.protocol = "http...

JavaScript can access the current URL in parts. For this URL:
http://css-tricks.com/example/index.html

window.location.protocol = "http"
window.location.host = "css-tricks.com"
window.location.pathname = "example/index.html"

So to get the full URL path in JavaScript:
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
If you need to breath up

Hot in Week

Popular

Archive

item