// url of the sript var scriptUrl = document.getElementById( 'uwm_cm_integration' ); // get lineup key, repo, and host from script url var dealerCode = getParameterByName( 'd', scriptUrl.src ); var repo = getParameterByName( 'r', scriptUrl.src ); var hostName = extractHostname( scriptUrl.src ); // get ymm from parent window var ymm = getParameterByName('ymm'); // create iframe url var iframeUrl = '//' + hostName + '/' + repo + '/front?d=' + dealerCode + '&type=integration'; iframeUrl += ( ymm ? '&ymm=' + ymm : '' ); // main container element var uwmIframeContainer = document.getElementById('uwm_cm'); // create pym script and add it to the dom var pymScript = document.createElement('script'); pymScript.src = '//' + hostName + '/cishared/js/pym/pym.js'; // setup iframe uwmIframeContainer.innerHTML = "
"; // append pym script to main container uwmIframeContainer.appendChild( pymScript ); /** * Get param from URL by name * * @param name of the param you are looking for * @param url to look for the param in by name * * @return String value of the param found */ function getParameterByName( name, url ) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } /** * Get host from url string * * @param url to look for the param in by name * * @return String value of the host found */ function extractHostname( url ) { var tmp = document.createElement ('a'); tmp.href = url; return tmp.hostname; }