Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the domain and page name from a String URL

Well i'm currently have some issue about manipulating an URL.

Technically what i want is to get the domain name and the page name from a page.

For example :

www.myWebSite.com => domain : myWebSite
http://myWebSite.com => domain : myWebSite
myWebSite.com/xxx.hmtl => domain : myWebSite page : xxx
like image 629
Sindar Avatar asked Mar 17 '11 18:03

Sindar


1 Answers

window.location.hostname; //Domain name

$("title").text(); //Page name

EDIT:

var loc = window.location;

var filename = loc.pathname.split("/");
filename = filename[pathname.length-1];

alert("Domain: "+loc.hostname);
alert("Filename: "+filename);
like image 133
mattsven Avatar answered Oct 16 '22 06:10

mattsven