0

In service.js, it employs the follwoing code to get the current url

var url = window.location.href.substring(0, (window.location.href.lastIndexOf("/")) + 1);

many javascript tutorials on the web suggest that window.location.href is enough to get the current url, so what is the purpose of the rest of the code?

1

It splits the url, by removing the filename. Suppose the url would be http://localhost/pset8/index.html. It now creates a substring starting at the 0th character, until the index, which contains the last "/". In this case it would be 23, the +1 is needed, so that the url still contains the last "/". You now could append other filenames, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .