I am creating a script which detects and returns the page name. However when there is a query string, it doesn't return the value I want for the "url_segment".
Can somebody show me how I can remove the query string and return the values for the variables "url" and "url_segment"
// http://test.com/action
// http://test.com/action/all
// http://test.com/action/all?page=2
function return_page_name()
{
var url = $(location).attr("href").split("/")[3]; // returns "action"
var url_segment = $(location).attr("href").split("/")[4]; // returns "all" (if selected)
if(url === "")
{
page = "homepage";
}
else if(url === "signup") {
page = "sign-up";
}
return page;
}