I have code:
function _filter() {
var url = window.location;
alert(url);
alert(url.split("/")[1]);
}
When I launch it I get only one alert message:
http://localhost:8000/index/3/1.
Why I don't get the second alert message?
Adding .toString()
works and avoids this error:
TypeError: url.split is not a function
function _filter() {
var url = window.location;
alert(url);
alert(url.toString().split("/")[2]);
}
When run on this very page, the output is:
stackoverflow.com
The location object is the cause of this, window.location is an object not a string it is the location.href or location.toString().
function _filter() {
var url = window.location.href; // or window.location.toString()
alert(url);
alert(url.split("/")[1]);
}
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