Skip to content Skip to sidebar Skip to footer

How To Extract Page Name From Complex Url

let's say we have this: http://www.domainname.com/somepage.php?c=innerContent How to retrieve with jQuery only the page name: somepage.php thx

Solution 1:

var url = "http://www.domainname.com/somepage.php?c=innerContent";
var temp = url.split("?")[0].split("/");
var pageName = temp[temp.length - 1];

Solution 2:

Use window.location.pathname. This will give you a leading / but that can be easily stripped out. More information is available on MDN for the window.location object.

Solution 3:

In JavaScript you simply need location.pathname.substring(1).

Solution 4:

window location

var xlastPart = window.location.pathname.split("/").pop()

A Link

var lastPart = jQuery("a:eq(3)").attr("pathname").split("/").pop()

Post a Comment for "How To Extract Page Name From Complex Url"