Why am I getting...
Uncaught TypeError: string.split is not a function
...when I run...
var string = document.location;
var split = string.split('/');
Change this...
var string = document.location;
to this...
var string = document.location + '';
This is because document.location is a Location object. The default .toString() returns the location in string form, so the concatenation will trigger that.
You could also use document.URL to get a string.
toString() instead of hacky concatenation?parseInt() and parseFloat(). There is also Number(). The + is shorter of course, but less readable for someone not used to hacky code or less experienced.+ '' method doesn't change anything for me in Chrome Browser but toString() does.run this
// you'll see that it prints Object
console.log(typeof document.location);
you want document.location.toString() or document.location.href
document.location isn't a string.
You're probably wanting to use document.location.href or document.location.pathname instead.
document.locationis an object. Try:var string=document.location.href