Созонов Алексей

Веб-разработчик

Получить url javascript

09.08.2015

http://example.com/example/index.html

window.location.protocol = “http” window.location.host = “example.com” window.location.pathname = “example/index.html”

Полный url

var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;

Разделить url http://example.com/blah/blah/blah/index.html

var pathArray = window.location.pathname.split( '/' );

Выбрать значение

var secondLevelLocation = pathArray[0];

Соединить все обратно

var newPathname = "";
for ( i = 0; i < pathArray.length; i++ ) {
  newPathname += "/";
  newPathname += pathArray[i];
}
#JavaScript‏‎