window.location.url Javascript

javascript

Solution

Use `href`:

window.location.href

For example running it on current SO page gives:

console.log(window.location.href);

this:

http://stackoverflow.com/questions/10783322/window-location-url-javascript

Problem

I'm splitting the current url into pieces but I'm doing something wrong with this part to get the current url. How can I solve this? ``` var url = window.location.url; ``` I'm trying to get the current url from the page. This is my function ``` function split(){ var url = window.location.url; // This part is not correct var firstSplit = url.split('?')[1]; var name = firstSplit.split('&')[0]; var age = firstSplit.split('&')[1]; var parName = name.split('=')[0]; var nameName = name.split('=')[1]; var parAge = age.split('=')[0]; var ageAge = age.split('=')[1]; document.getElementById("nameId").innerHTML=naamName; document.getElementById("ageId").innerHTML=leeftijdAge; } ```

Original source