var pathArray = window.location.href.split( '/' ); var rootPath = ""; for (i = 0; i < pathArray.length - 1; i++) { rootPath += pathArray[i]; rootPath += "/"; } var templatePath = rootPath + 'templates/new_tample/'; var lastSegment = window.location.pathname.split("/").pop(); if (lastSegment == ''){ lastSegment = window.location.search.replace( '?', '').split("=").pop(); } var partnerName = '&partner=' + lastSegment;