본문 바로가기

개발

[javascript] base url 추출

728x90

 

 

javascript - base Url 추출

var getUrl = window.location;

//http://www.naver.com/test
console.log("전체주소 : " + getUrl);
	
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];

//http:
console.log("getUrl .protocol : " + getUrl .protocol);

//www.naver.com
console.log("getUrl.host : " + getUrl.host);

//test
console.log("getUrl.pathname.split('/')[1] : " + getUrl.pathname.split('/')[1]);

//http://www.naver.com/test
console.log("baseUrl : " + baseUrl);

https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript

 

How to get base url with jquery or javascript?

In joomla php there I can use $this->baseurl to get the base path, but I wanted to get the base path in jquery. The base path may be any of the following example: http://www.example.com/ http://

stackoverflow.com

 

728x90
반응형