• 0

    Get base url using Javascript

    by Asmin

    A simple javascript function to get the website base url.

    
    function getBaseUrl(){
    	var getUrl = window.location;
    	var urlArr = getUrl.pathname.split('/');
    	var baseUrl = getUrl.protocol + "//" + getUrl.host;
    	if(getUrl.host == 'localhost' || getUrl.host == '127.0.0.1' || getUrl.host == 'yourLocalHostIp'){
    		baseUrl += '/'+urlArr[1];
    	}
    	return baseUrl;
    }
    


Leave a Comment

Please Login to insert comment.